I need to save a plot. This is my code that I don't know why it does not work.
hold on;
plot(x1, y2)
plot(x1, y2)
print -djpg image.jpg
The plot in output on screen is correct, but the output in the file is different: it saves only an empty plot image without my points.
This is my output in the file:
Plots panel –> Export –> Save as Image or Save as PDF Specify files to save your image using a function such as jpeg(), png(), svg() or pdf(). Additional argument indicating the width and the height of the image can be also used. Create the plot.
Octave can display more than one plot in a single figure. The simplest way to do this is to use the subplot function to divide the plot area into a series of subplot windows that are indexed by an integer. For example, subplot (2, 1, 1) fplot (@sin, [-10, 10]); subplot (2, 1, 2) fplot (@cos, [-10, 10]);
octave#:#> plot(x,y,'b--','linewidth',3) will plot x and y as a thick, blue, dashed line. The next example consists in plotting two different functions on the same axis. Specifically, we will plot the functions f1(x) = sin(x) and f2(x) = sin(x2) from x = 0 to x = 2π, using equally spaced points on the x-axis.
If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca . The optional return value h is a graphics handle to the created scatter object. Example: x = randn (100, 1); y = randn (100, 1); scatter (x, y, [], sqrt (x.
During intermediate stages it is often better to save the graphics object and all of its associated information so that changes—to colors, axis limits, marker styles, etc.—can be made easily from within Octave. The hgsave / hgload commands can be used to save and re-create a graphics object.
Mathematics is incomplete without visualization, without drawing the results, and without plotting the graphs. octave uses the powerful gnuplot as the backend of its plotting functionality. And in the frontend provides various plotting functions. Let’s look at the most beautiful ones.
GNU Octave: Printing and Saving Plots Next: Interacting with Plots, Previous: Use of the interpreterProperty, Up: High-Level Plotting [Contents][Index] 15.2.9 Printing and Saving Plots The printcommand allows you to send plots to you printer and to save plots in a variety of formats.
We can use multiple commands at a time by separating them with a comma (,) in Octave environment. Writing code in comment? Please use ide.geeksforgeeks.org , generate link and share the link here.
I just had the same issue with the latest Octave (3.8.1). This issue comes from GhostScript, not Octave. There's a bug with the management of fonts.
To make sure, check in your console after you try to print if this error is outputted (along with a lot more infos):
GPL Ghostscript 8.63: Unrecoverable error, exit code 1
If that's the case, then try this:
set (0, "defaultaxesfontname", "Helvetica") % this is the line to add BEFORE plotting
hold on;
plot(x1, y2)
plot(x1, y2)
print -djpg image.jpg
This will fix the problem by setting a font that GhostScript can handle without any issue. Note that if you already plotted the figure, you will have to close it and replot it after setting defaultaxesfontname.
Source: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=710272
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With