i am looking for a way to display just special values on the x-axis in a plot of a function on SageMath. (e.g. 0, pi/4, pi/2, 3pi/4, pi, ...)
Any suggestions?
The SageMath plotting documentation
has examples of using ticks and tick_formatter.
They allow plots like the following:
sage: ticks = [pi/6, sorted({sin(a) for a in [0, pi/6 .. 2*pi]})]
sage: p = plot(sin, 0, 2*pi, ticks=ticks, tick_formatter=pi)
sage: p
Launched png viewer for Graphics object consisting of 1 graphics primitive
To save the plot:
sage: p.save('sine_function_plot.png', figsize=5)
Related
Ive been working with adjustments and I have coordinates and I need to plot a sphere with wireframe, I need to draw these points and this sphere on the same graph, how to do this using GLMakie in Julia? I can use wireframe and scatter separately, but not both at the same plot.
And also, how can i change the center of the sphere with the command Sphere(Point3(1,5)?
I tried it..
x = [0, 1]
y = [0, 1]
z = [0, 1]
scatter!(x, y, z, markersize=[0.2,0.0])
wireframe!(Sphere(Point3(1),5), limits=FRect3D([-5,-5,-5],[10,10,10]))
but returned: Combined{Makie.wireframe, Tuple{Sphere{Int64}}}
you need to display the figure, the quick and dirty way is to run
current_figure()
To plot a circle of radius 2 centered at (1, 1) I do the following:
θ = 0:0.1:2π
x = 1 .+ 2cos.(θ)
y = 1 .+ 2sin.(θ)
plot(x, y, aspect_ratio=:equal)
However, if I want to plot a set of parametric equations with more than two parameters I cannot use this approach. How should one approach plotting parametric equations with more than one parameter in Julia? For instance, how can I plot the cone described by the parametric equations
x = r*cos(θ)
y = r*sin(θ)
z = r
where r and θ are the parameters?
I am imagining the final plot to look like in the below image that has been generated by entering ParametricPlot3D[{r*Cos[t], r*Sin[t], r}, {r, -3, 3}, {t, 0, 2*Pi}] in Mathematica.
This works with the plotly and pyplot backends to Plots but not gr:
X(r,theta) = r * cos(theta)
Y(r,theta) = r * sin(theta)
Z(r,theta) = r
rs = range(0, 2, length=50)
ts = range(0, 2pi, length=50)
surface(X.(rs',ts), Y.(rs', ts), Z.(rs', ts))
R's abline draws a straight line parameterised by y = ax+b on the x-y 2D coordinate plan.
What's Julia's equivalent of that in Plots.jl?
There is Plots.abline! which draws a straight line in the form of ax+b respecting axis limits of the plot. So it will not actually go to infinity but does not require you to know what the axis limits are beforehand.
plot(x->((x^2+3x+2)/(x-2)), 6, 30, xlim=(6,30), size=(300,300))
# draw oblique asymptote to the above function (y=x+5)
Plots.abline!(1, 5, line=:dash)
You can also plot a straight line using only two points that are on the line. This should also respect the axis limits.
plot!([x1, x2], [y1, y2], seriestype = :straightline, kwargs...)
Is there a simple way of plotting a function f(x,y,t) = Exp[t-x-y] by setting the time t? I've tried several variations of
Plot3D[Evaluate[f[t,x,y],t->0],{x,0,1},{y,0,1},PlotRange -> All]
But I can't get it to work. I want to be able to change t and see how the plot changes, but I'm also using the equation f for a differential equation so I'm taking partials and I need t to be symbolic for other parts of the notebook. Or is there a way to make a plot video that updates with time?
Expanding on the comments.
Interactively manipulate the plot
f[x_, y_, t_] := Sin[t x] Sin[t y]
Manipulate[Plot3D[f[x, y, t], {x, -Pi, 2 Pi}, {y, -Pi, Pi}], {t, 0, 3, 1/8}]
Generate a list of plots
plots = Table[Plot3D[f[x, y, t], {x, -Pi, 2 Pi}, {y, -Pi, Pi}], {t, 0, 3, 1/8}];
Export the plots to an animated GIF
Export["plots.gif", plots]
I want to plot two functions in different ranges in Gnuplot. As an example, I want to plot f(x) for xrange [0:0.5] and g(x) for xrange [0.5:1], both in a same graph.
What should I do for this?
You have at least two different solutions :
1) create a "heavyside" function :
f(x) = ... define your first function
g(x) = ... define your second function
h(x) = (x<0.5)?f(x):g(x)
plot h(x)
2) if you need some control on the color of each function, you could do
plot (x<0.5?f(x):1/0) lc 1, (x>0.5?g(x):1/0) lc 2