I am trying a simple plot using
x = linspace(0, 10, 200); y = sin.(x);
plot(x, y, "b-", linewidth=2)
And the result is simply PyObject
<matplotlib.lines.Line2D object at 0x1249b77f0> and no graph!
I tried the same in Jupyter and the graph is showed. Why?
First I would try if you can display the current figure with:
If nothing appears you may have to install a Python GUI toolkit as it is outlined in the documentation:
display(gcf()) shows the current figure.
If you’re going to be doing a lot of interactive plotting then it’s better to turn on the interactive plotting mode.
display(gcf()) should not be necessary.
I tried do plot with
ion() and without
display(gif())with no success.
Another possibility is to use PyPlot as the plotting backend with Plots.jl.
display(gcf()) is not necessary and VS Code shows the plot immediately.
Added to this is the benefit that you can switch easilly to one of the 15 different plotting backends.
x = linspace(0,2*pi,1000); y = sin.(3 * x + 4 * cos.(2 * x));
plot(x, y, color="blue", w=2)
Yes it seems a better solution.
But I noticed that the syntax for the command
winstead of “b-“ and
Is it due to
Plots.jl is a common interface to the various backends. Not all the keywords for all backends are supported though. A dedicated list of supported attributes is provided in the documentation to the package.
Some examples for PyPlot are here:
Thank you for showing me the link to the
Plots site. It is very interesting and useful.
I have this piece of code that works in REPL, but not in vscode.
img = testimage(‘cameraman’)
Why?, Any ideas?
now I see that I need to use ImageView.
I open another thread…