The plot is generated by the following commands in Maxima. How can I add dots / markers at given coordinates?
load(implicit_plot);
ip_grid_in:[15,15]$
implicit_plot ([x^2 = y^3 - 3*y + 1, y=x^2], [x, -4, 4], [y, -4, 4],
[gnuplot_preamble, "set zeroaxis"]);
I have tried adding [discrete, [[1.0,1.0], [1.0, 2.0]]] to the list of equations but apperantly implicit_plot cannot handle it (perhaps because it is not an equation).
I'm no maxima wizard, but in gnuplot, I would add points using set label.
set label 1 at 1,1 point
set label 2 at 1,2 point
Based on what you have above, I would think you could just add this to the preamble:
implicit_plot ([x^2 = y^3 - 3*y + 1, y=x^2], [x, -4, 4], [y, -4, 4],
[gnuplot_preamble, "set zeroaxis;set label 1 at 1,1 point;set label 2 at 1,2 point"]);
It's a bit ugly, but I'm betting that it works :)
Of course, you may need to unset those labels in a later preamble if maxima re-uses the same gnuplot instance and doesn't issue a reset implicitly:
unset label 1; unset label 2
There are lots of things you can do to customize the appearance of the points (color, point-type, etc). in gnuplot, help label should discuss a bunch of those options if you're interested.
Related
I am plotting multiplot surfaces.
I found this code 1 very helpful to plot my graph.
However, I want to label the z-axis throughout all surfaces in one plot.
I tried this set zrange[0.5:b+0.5], but nothing showed up. then I tried min_z and max_z, still, nothing showed up.
though I calculated and checked the range by the following the command.
print min_z,max_z.
can anyone please tell me how can I choose zrange with my own choice? like 1 ,2 3 4 5.
I will expand my comment as a possible answer. Multiplot is not needed for this style of plot. Here is an approximate recreation of the figure you linked to.
If you want to customize the axis labels along z, you can add a command to change the format like this: set ztic format "%.2f", and/or add additional commands of the form: set ztic add ( pi/2 "z = π/2" )
f(x,y,z) = besj0(x*x/z + y*y/z) / z
set palette cubehelix
set xyplane 0
set view 64,58
set ztics 0.2
unset key
splot for [i=1:6] z=(1.+i/6.), '++' using 1:2:(z):(f(x,y,z)) with pm3d
Answer expanded to show plotting from a series of files
Plotting from a series of files is essentially the same. The splot command again inserts a constant z value to create a plane, taking the data coordinates [x,y] from columns 1 and 3 and the f(x,y) value from column 4.
Here is an example:
set palette defined( 0 "dark-red", 1 "yellow" )
set xyplane 0
set view 74, 62, 0.85, 1.8
set border 16 # z axis only
unset xtics; unset ytics
unset key
file(i) = sprintf("map%d.dat",i)
set ztics ("File 1" 1, "File 2" 2, "File 3" 3, "File 4" 4)
splot for [i=1:4] file(i) using 1:2:(i):3 with image
I'm making new bar diagram in my OCTAVE application. Because of the better readings I want to add actual values for each bar. The actual values of each bar column should be located on the high Y=50% and centrally centered with each bar column. I have search over the google, but I didnt found any real example of values over the bar columns.
My example made in paint, how should look:
Picture above is a example how should look - for example purposes there are RED colored values of the each bar column.
Code of the plotting of this bar diagram:
subplot(5, 1, 5);
y2 = [data1; data2; data3; data4];
x = [1 ,2 ,3, 4];
labels = ["DATANAME1"; "DATANAME2"; "DATANAME3"; "DATANAME4"];
bar (x, y2, 0.5, 'facecolor', [0, 0.5, 1]);
set(gca, 'xticklabel', labels);
title("Something [%]");
xlabel('XLABEL');
ylabel("%");
You can use the text command for putting any text on/over any plot.
Here's my suggestion, I slightly re-worked your code:
% Data
x = [1, 2, 3, 4];
y2 = [2; 52; 3; 43];
% Original plot
bar(x, y2, 0.5, 'FaceColor', [0, 0.5, 1]);
labels = ['DATANAME1'; 'DATANAME2'; 'DATANAME3'; 'DATANAME4'];
set(gca, 'XTickLabel', labels);
title('Something [%]');
xlabel('XLABEL');
ylabel('%');
% Additional plot
y = max(y2) / 2; % "located on the high Y=50%"
values = [num2str(y2) repelem(' %', 4, 1)];
text( x - 0.1, ... % x values to put text (some negative displacement for "centrally centered with each bar column")
repelem(y, 4, 1), ... % y values to put text (four times y)
values, ... % Actual values as text plus "%" to put
'Color', 'r', ... % Red text
'FontWeight', 'bold'); % Bold text
The output then looks like this:
I used Octave 5.1.0, the repelem command might not be available before Octave 5.x, but there are alternatives to achieve what repelem does.
Notice, the construction of values (only) works, because y2 is a column vector. Otherwise, adding the "%" to each value in y2 might be a bit more complicated.
Hope that helps!
I wanted to plot a user-defined Piecewise function (pagoda function) in Mathematica 10.2.
It seems straightforward to me unfortunately the easy command leads to a bad result.
My first approach was:
f[x_] := Piecewise[{{0, x <= -1}, {-Abs[x] + 1, -1 < x < 1}, {0,
x >= 1}}]
Plot3D[ 5*f[x]*f[y], {x, -1.5, 1.5}, {y, -1.5, 1.5}]
I also tried to set MaxRecursion which lead to more terrible results in a few cases (e.g. 2,3).
Can anybody tell me how to plot this function in a smooth nice way?
Thanks,
Felix
As far as I can remember, making visible gaps was introduced as a feature. Before that, piecewise or discontinuous functions were plotted like this:
Plot[Piecewise[{{x, x <= 1}, {3, x > 1}}], {x, 0, 3}, Exclusions -> None]
That behavior gives the wrong impression. I would have to check when this was default or if I'm completely off here. Anyway, as already noted in the comments, you can use the Exclusions option to get connected graphs.
You don't need to increase PlotPoints because Mathematica will (hopefully always) recognize the boundaries of the pieces as places where it needs to recursively increase points. Therefore, the MaxRecursion option is far more important to give a smooth plot. This example was rendered with only 10 points, but a recursion value of 5:
Therefore, your function renders extremely well even with 10 plot-points when the recursion is high enough. Look how many subdivisions you get on the cracks
Plot3D[5*f[x]*f[y], {x, -1.5, 1.5}, {y, -1.5, 1.5}, PlotRange -> All,
Exclusions -> None, PlotPoints -> 10, MaxRecursion -> 6, Mesh -> All]
Finally, note that the gaps are not restricted to Piecewise functions. As you can verify yourself, UnitStep will also show gaps. You can try it with your example by using an undocumented function to turn everything to UnitStep:
Simplify`PWToUnitStep[5*f[x]*f[y]]
(*
5 (1 - Abs[x]) (1 - Abs[y]) (1 - UnitStep[-1 - x]) (1 -
UnitStep[-1 + x]) (1 - UnitStep[-1 - y]) (1 - UnitStep[-1 + y])
*)
With all due respect to #halirutan, by itself MaxRecursion set to 6 was not enough in the following plot to adjust the peak values of a piecewise function to be a monotonic increasing sequence:
This improved, when, in addition, I set PlotPoints to 240, as follows.
However, that does not completely solve all the display problems. For example, note in the plots above, that the initial value y = 0, is not correctly plotted as a blue vertical line despite use of Exclusions->None. Moreover, the grid lines, which are Dotted, do not display as dots, but as dashes which run off below the x-axis. All of these problems can be solved, probably more efficiently, by generating the points or dots as list data and using ListPlot or, as in this case ListLogPlot and using Joined->True when appropriate. That is low level solution, but is needed in more complicated plots to obtain a plot with shorter run time and more accessible control over the display features.
I have a samples list with a collection of (x,y) coordinates pairs. I want to use plot2d to create a discrete plot from these points, not showing lines connecting each point.
This is my script:
plot2d(
[discrete, samples],
[style, [points, 1, 5, 1]],
[legend, "Samples"],
[gnuplot_term, "svg size 640,480"],
[gnuplot_out_file, "graph_samples.svg"]
)$
But the result is a plot with connected points, as can be seen in the picture below. Despite the use of the [style, [points, 1, 5, 1]] option, the plot connects each point. The style definition seems to be ignored.
Does anyone have a clue why is this happening? I know I could alternatively use draw2d but I'd rather use plot2d if possible.
You can also quote a symbol to prevent evaluation:
points: [1, 2, 3];
x: 42;
plot2d('x^2, ['x, 1, 2], ['style, 'points]);
The problem was that I had a points matrix previously declared that was conflicting with the style definition. Changed its name and worked like a charm.
Example
Suppose I have two triangles:
A triangle with points (0, 0), (10, 0), (10, 0.5) and
a triangle with points (0, 0), (1, 0), (0.5, 11)
The resulting two plots without specifying the xlim and ylimlook like this:
Question
What do I need to do to satisfy all points listed below?
Make the triangle visible, so that no line of the triangle is hidden by an axis
Specify the same margin for all plots in mm, cm or other unit.
(in the example above only two triangles were used. Actually I have n triangles.)
As margin I mean the distance between the outer points of the triangle and the axis.
The resulting plots should look like this
with the difference that the distances, which are marked with the red arrows, should all be the same!
I don't know of a way to to it in cm/mm, but you can do it with the precentage of the total size:
# you don't really need this see bellow
#from matplotlib.backends.backend_pdf import PdfPages
import pylab
import matplotlib.pyplot as plt
left,bottom,width,height = 0.2,0.1,0.6,0.6 # margins as % of canvas size
fig = plt.figure(figsize=(4,4),facecolor="yellow") # figure size in Inches
fig.patch.set_alpha(0.8) # just a trick so you can see the difference
# between the "canvas" and the axes
ax1 = plt.Axes(fig,[left,bottom,width,height])
ax1.plot([1,2,3,4],'b') # plot on the first axes you created
fig.add_axes(ax1)
ax1.plot([0,1,1,0,0], [0,0,1,1,0],"ro") # plot on the first axes you created
ax1.set_xlim([-1.1,2])
ax1.set_ylim([-1.1,2])
# pylab.plot([0,1,1,0,0], [0,0,1,1,0],"ro") avoid usig if you
# want to control more frames in a plot
# see my answer here
#http://stackoverflow.com/questions/8176458/\
#remove-top-and-right-axis-in-matplotlib-after-\
#increasing-margins/8180844#8180844
# pdf = PdfPages("Test.pdf")# you don't really need this
# pylab.savefig(pdf, papertype = "a4", format = "pdf")
# automagically make your pdf like this
pylab.savefig("Test1.pdf", papertype="a4",facecolor='y')
pylab.show()
pylab.close()
# pdf.close()
and the output is:
corrected image:
Your two triangles with points (0, 0), (10, 0), (10, 0.5) and (0, 0), (1, 0), (0.5, 11) would be represented in pylab as:
Ax = [0, 10, 10]
Ay = [0, 0, 0.5]
Bx = [0, 1, 0.5]
By = [0, 0, 11]
pylab.plot(Ax, Ay)
pylab.plot(Bx, By)
Let's see what the lowest X value is:
lowestX = None
for x in Ax+Bx:
if lowestX==None or x<lowestX:
lowestX = x
Exercise for the reader to do the same for highestX, lowestY, and highestY.
Now, consider a boundary of 2 units, you can add / subtract these units from the lowest and highest values and set xlim and ylim:
margin = 2
pylab.xlim([lowestX-margin, highestX+margin])
pylab.ylim([lowestY-margin, highestY+margin])