How do I graph a line in Julia with an arrow on both sides? - julia

Here is my code:
using MTH229
using Plots
f(x)=x
theme(:dark)
plot(f,-5,5,linewidth=5,c=:hotpink,legend=false,arrow=true)
Here is a picture of the output:
plot
How do I get the arrow to appear on both ends of the line instead of just one?

The plot and plot! commands have an arrow parameter that in turn has a special option :both to have arrows on both ends. Hence you can just do
plot(f,-5,5,linewidth=5,c=:hotpink,legend=false,
arrow=Plots.Arrow(:open, :both, 2.5, 2.0))

It's a bit of a hacky solution, but for the example in the question:
plot!([-4.99,-5],[f(-4.99), f(-5)],
linewidth=5,c=:hotpink,legend=false,arrow=true)
adds the reverse arrow. Generalizing to any chart is pretty straight forward. The idea is to draw a line chart with a reverse direction, for just a tiny bit at the location of the reverse arrow and let Plot add the reverse arrow.

Related

How to Draw the Solution Curve in Julia with Arrow Correctly Using Plots?

I am trying to plot the solution curve from this page:
dynamicalsystem
But, I can't draw the arrow in the curve pointing to the origin, and the curve is not spiraling as well. Is something wrong with my code?
using MTH229, ForwardDiff, Plots, LaTeXStrings, SymPy
gr()
t = range(0, stop=21, length=10000)
x = #. exp(-2t)*cos(t)
y = #. exp(-2t)*sin(t)
plot(x, y, arrow = :closed, label=L"x(t)",
xlims=(-0.1,1), ylims=(-0.1,0.21))
You do not see a spiral, because the plot you have linked is not accurate (i.e. it has a wrong scale - most likely for didactic purposes). You can see that you have a spiral, by e.g. plotting the angle of the point plot(t, angle.(x + im * y)). The problem is that the plot absolute value of the points you plot gets very small very fast so these spirals are not visible.
Now the other issue is how to plot the arrow. The arrow in your case is just not visible because it is plotted at the end of your curve. I think (but maybe there are better ways to do it) that the simplest solution to pick a place to add it separately. For example after doing an initial plot add plot!(x[240:241], y[240:241], arrow=:closed) will add an extra arrow in the segment of your curve and the arrow will be visible (you just need to decide on the color of the arrow).

Put Y-Axis along x=0 line in Bokeh figure

I would like to have my y-axis go right up through the x=0 line in my figure, rather than have it on the left side. Is there an easy way to achieve this with Bokeh?
Currently not available in Bokeh, as of 0.12.1. There is an open issue for this feature.
Have seen someone visually faking it using spans when replicating this infographic - but note labels still off to the left.
Here's the mailing list discussion: https://groups.google.com/a/continuum.io/forum/#!topicsearchin/bokeh/fivethirtyeight/bokeh/_dKphJePDwg
I was attempting to do this and it looks like there is now a solution to this. You can set the figure.yaxis.fixed_location attribute to zero.
As an explicit example using bokeh 1.0.4:
# ... bokeh imports
p = figure(plot_width=300, plot_height=300)
p.patch([-1,0,1], [-1,1,0.5], alpha=0.5)
p.yaxis.fixed_location = 0
show(p)
returns the figure:
You can also do this for the x-axis or both.

Why did I get a different result-plot between the two solutions?

>
Hi,
I'm using a sample problem to learn the comsol.
I would like to let my case problem (left)
3D plot, be the same as the tutorial plot (right).
My problem is that, instead of the right figure plot (that shows the resin-red color traveling from the left edge to the right one), I'm getting the nonconforming left one.
Do you have an idea if there is a choice of getting the right plot, or an advice about why I get the left plot instead of the right?
Thank you in advance!
Panos Deemac
Your problem is the Colorbar. In the left the color goes up to 1x10^5 while in the right it goes to 1, thus drawing as red everything above 1. Change the color limits to the same, and you'll get the same plot.

Trying to make twoord.plot interactive

I have a plot that I created using thet twoord function. I am trying to make it an interactive graph so that I can hover around a point with my mouse and see what the x,y coordinates are for that plot.
I can't figure out how to do this with the twoord.plot function. Any idea how to do this?
My apologies, I was misreading the R command for identify. FYI, just place this code: identify(x, y, labels=row.names(mydata)) after the plot command and you are able to select points accordingly.

ggplot2 polar plot axis label location

This is just a extension for a old question
ggplot2 polar plot arrows
You will find the x axis is out of the most_out circle.
In ggplot2, I use "panel.grid.major = theme_line(colour = "black", size = 0.2, linetype=2)" to get the dashed circle, just as below:
So my question is how to make the axis label (180, 135, 90, .....) outside of the circle, because the text are merge with the circular lines.
I try to use "hjust" or "vjust" to adjust the distance between text and axis. But it does not work.
So do you have some ideas about this problem?
Thanks first!!!!
You have not provided code to reproduce the problem so this will be just a guess.
I've used whitespace, \n in particular, to move text "away" in the past. Perhaps a custom formatter might work here. Here is how you can write a custom tick mark label formatter.
If this fails, you can always hide the axis labels and paint them yourself using geom_text by adding another layer.
Hope this helps. #hadley's book on ggplot2 is very good, by the way.
I came across this question while I was trying to fix a similar issue myself. One workaround is pretty much covered in the answer to this post: Remove extra space and ring at the edge of a polar plot
You would have to adjust the limits of the x scale to match your axis labels. You would also have to create a new scale bar corresponding to the radial length of your arrows (the 0-300 scale bar on the left side of your plot), since
axis.text = element_blank
takes the scale bar away as well.

Resources