I am using Julia in Atom on a MacBook Pro and I do not succeed in getting a plot Window within or outside Atom when I use PyPlot.
Here is the package status :
....
(v1.1) pkg> status
Status `~/.julia/environments/v1.1/Project.toml`
[c52e3926] Atom v0.8.2
[7073ff75] IJulia v1.18.0
[e5e0dc1b] Juno v0.7.0
[d330b81b] PyPlot v2.8.0
[ade2ca70] Dates
...
I try the following code :
...
using PyPlot
plot(rand(10))
...
And I get :
...
1-element Array{PyCall.PyObject,1}:
PyObject <matplotlib.lines.Line2D object at 0x12963c9e8>
....
If I try :
...
plt.show()
...
I get :
...
/Users/Didier/.julia/conda/3/lib/python3.7/sitepackages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())
...
There are plenty discussions about Backends with PyPlot (i.e. Matplotlib inside Julia) but nowhere I found a rationale to modify the backend used by Matplotlib within Atom.
Does somebody have a clear idea about this?
Thanks in advance.
Use PyPlot.display_figs() as in this example:
using PyPlot
plot(1:5,(1:5).^2)
PyPlot.display_figs()
When working in the console PyPlot.show() could be a good idea.
Finally, you can always just save your picture to a file with the savefig command e.g. savefig(raw"c:\temp\aa.png")
Related
I am trying to use Jupyter for Julia in vscode:
using PyPlot
a = [1,2]
b = [2,3]
fig=figure(1)
PyPlot.plot(a, b, linewidth=1)
PyPlot.scatter(a, b)
show()
When I run this a new window will pop up. What I want to do is to prevent it to pop up and see the picture below my codes. After doing some search it seems in Python you can solve it by %matplotlib inline, but how do I sovle it in Julia?
Try gcf() instead of show.
gcf yields the current PyPlot Figure object and it will be automatically rendered by Jupyter:
I'm using sublime text 3 with REPL in python. My version of Python is python 3.5#64bits. It's not the Anaconda distribution, but a standalone version. I have been using pandas and numpy for a while without any troubles.
I am having trouble plotting with Matplotlib : my interpreter stop running after having call the show() method on a figure.
Using this code snippet, from the matplotlib documentation :
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
I get the following result. The second print("test") is never evaluated, and i have to restart REPL even if i close the plot's window.
My REPL settings are the following :
{
"cmd": ["C:\\Documents \\Sublime \\python-3.5.3.amd64\\python.exe", "-i", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell": true
}
I have so far tried to :
Switch matplotlib backends
According to matplotib documentation : I have switched to the interactive mode with ion() method / with the matplot.interactive(True)
Reinstall matplotlib
Use matplotilb wit bloc=False param
Does anyone know how to get the interpreter working after having plot ? Thanks in advance.
I am creating plots using matplotlib and mpld3 (both successfully installed) but when plotting I got this error message:
...File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in init#012 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)#012TclError: no display name and no $DISPLAY environment variable.
Any idea how to solve that?
thanks for your help
Try this
import matplotlib
matplotlib.use('Agg')
Check this page for more informations
I am a heavy user of jupyter notebook and, lately, I am running it using pypy instead of python to get extra speed. It works perfectly but I am missing matplotlib so much. Is there any decent 2D plotting library compatible with pypy and jupyter notebook? I don't need fancy stuff, scatter, line and bar plots would be more than enough.
Bokeh is working fairly good with pypy. The only problem I have encountered is linked to the use of numpy.datetime64 that is not yet supported by pypy. Fortunately it is enough to monkey-patch bokeh/core/properties.py and bokeh/util/serialization.py to pass in case of datetime64 reference.
I did it in this way:
bokeh/core/properties.py
...
try:
import numpy as np
datetime_types += (np.datetime64,)
except:
pass
...
and
bokeh/util/serialization.py
...
# Check for astype failures (putative Numpy < 1.7)
try:
dt2001 = np.datetime64('2001')
legacy_datetime64 = (dt2001.astype('int64') ==
dt2001.astype('datetime64[ms]').astype('int64'))
except:
legacy_datetime64 = False
pass
...
And managed to get nice looking plots in jupyter using pypy.
Working in IJulia. Desperately trying to make a custom colormap.
Tried the line:
matplotlib.colors.ListedColormap([(1,0,0),(0,1,0),(0,0,1)],"A")
which resulted in the following error
type PyObject has no field colors while loading In[16], in expression starting on line 1
which apparently means that I cannot use matplotlib directly, but only the functions which are in PyPlot.
I cannot involve matplotlib with an import (as this is invalid in IJulia).
I have noted that others have had help on similar problems, but that doesn't solve mine.
By using the PyCall package which PyPlot is using to wrap matplotlib you can obtain a colormap like this:
using PyCall
#pyimport matplotlib.colors as matcolors
cmap = matcolors.ListedColormap([(1,0,0),(0,1,0),(0,0,1)],"A")
In order to access fields in a PyObject you need to index the object with a symbol like:
cmap[:set_over]((0,0,0))
This is equivalent to: cmap.set_over((0,0,0)) in python. For other good examples of how to plot different kinds of plots using PyPlot, see these examples: https://gist.github.com/gizmaa/7214002
You don't need to use PyCall to call Python directly (although this is, of course, an option). You can also just use the PyPlot constructors for ColorMap to construct a colormap from (r,g,b) arrays or an array of colors as defined in the Julia Color package. See the PyPlot ColorMap documentation. For example:
using PyPlot, Color
ColorMap("A", [RGB(1,0,0),RGB(0,1,0),RGB(0,0,1)])