pyplot while using X11 forwarding - python

I'm trying to setup my remote working environment so that I can use matplotlib.pyplot under ipython. My local machine and remote machine are both MAC OSX Mavericks. I've tried xeyes and it works properly so I think my X11 forwarding works fine. However, when I try functions in matplotlib.pyplot it didn't show any error message but I didn't see any figure either.
I know it's about which backend to use and I've tried using ipython --pylab=tk but didn't work. Tried to install pygtk but can't manage to install a dependency py2cairo (seems to be an open issue). Any other thoughts? Thanks.

How did you "try functions in matplotlib.pyplot"?
The following works for me
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()

Related

matplotlib plot window not showing in windows 11

I have recently upgraded my OS to windows 11, and installed conda as the python package manager. I am using windows terminal(v1.11) with powershell (v7.2), and python(v3.9), matplotlib(v3.5).
When trying to plot anything using matplotlib.pyplot, the plot window is not showing up anywhere.
I tried to specify the backend to be "qtagg" but it has no effect.
These is the python code
import matplotlib.pyplot as plt
plt.plot(1,1)
plt.show()
Does windows support pyplot window? Or some packages or setting are missing? Thank you very much.

How do I get Pyinstaller to work with pyplot?

I am trying to turn a program, that uses the matplotlib.pyplot module, into an executable.
The script itself works as intended when run in the terminal, but when I use the executable made by pyinstaller, it shows - "Script failed to execute".
I have narrowed down the issue to the following code:
import matplotlib.pyplot as plt
The .exe will run fine with this code commented out, but that way I am not able to plot graphs using pyplot.
EDIT: I did some research on this and found out it's a known issue with Matplotlib 3.3, so I was able to get around it by uninstalling the current version and using:
pip install matplotlib==3.1.3

Matplotlib does not show up on ubuntu windows subsystem

I have installed matplotlib on ubuntu windows subsystem and run this simple code:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1, 2, 3, 4])
plt.show()
But it just does not show up anything.
So I tryied to install matplotlib on windows powershell and then executed the same code and it worked well:
Well even know it worked fine using powershell I really want to run my programs using linux susbystem, what should I do?
WSL does not support graphics.
You need to setup X server for WSL.
Have a look at https://x410.dev/

Import package works in jupyter notebook but not in iPython and Anaconda cmd

When searching about this issue, I came across some questions asking the opposite, i.e., package opens in iPython but not in Jupyter Notebook. But in my case, its the opposite. That's why I posted this question.
I added path\to\anaconda3 and path\to\anaconda3\Lib\site-packages in the environment variable, but it doesn't solve the issue.
I can see the packages in the site-packages folder:
But I just can't import some of the packages in iPython:
or with python in the anaconda cmd:
But it works fine in Jupyter Notebook:
What do/can I do to fix this?
Here's some more info if it helps:
(base) C:\Users\h473>where python
C:\Users\h473\AppData\Local\Continuum\anaconda3\python.exe
(base) C:\Users\h473>where conda
C:\Users\h473\AppData\Local\Continuum\anaconda3\Library\bin\conda.bat
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\conda.exe
(base) C:\Users\h473>where pip
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\pip.exe
P.S.: It doesn't happen for all packages, only some packages, as shown for pandas, numpy and matplotlib in the screenshot below.
When you are using matplotlib (and seaborn is built on top of it) it needs to use a so called backend that is used to display the actual GUI with the plot in it once you execute for example matplotlib.pyplot.show().
When you are running a Jupyter Notebook with matplotlib in inline mode (default I think, but not sure), then a Jupyter specific backend is used (module://ipykernel.pylab.backend_inline). That makes sense, since the plots should not appear in separate windows, but be displayed inside the notebook itself.
When you are in an interactive python or iPython session however, Qt5 was used as
import matplotlib
print(matplotlib.rcParams["backend"]) # this prints the backend that would be loaded when trying anything with pyplot
has revealed. Since you get the error youa re getting, it looks like your QT5 installation is broken. You can try to reinstall them using the conda commands, but for now you could also fall back to using a different backend, that you need to specify before trying to load seaborn:
import matplotlib
matplotlib.use("TkAgg") #use backend TkAgg
import seaborn
You can also change the default backend being loaded to TkAgg by creating a matplotlibrc file in C:\Users\<your name>\.matplotlib\ with
backend : TkAgg
in it.

Matplotlib hangs during instantiation on Pixelbook

I am trying to set up a python3 development environment on my Pixelbook.
I enabled native linux app support on it by switching to developer branch, so now I have a working bash shell with apt.
I was able to install gvim and python3.5.3 and pip. I installed numpy, scipy, pandas and matplotlib fine. All the other packages work smoothly, and I can import matplotlib, but as soon as I try to call any method from matplotlib it hangs my shell and never returns.
Here is a simple scripts I use for testing:
import scipy as sp
import matplotlib.pylab as plt
t = sp.arange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))
plt.show()
I try to run it like this, but it never returns and Ctrl+C doesn't help either:
Command output
I tried using a different backend like this:
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
It doesn't help either.
Some people suggest using matplotlib.ion(), but it didn't change anything either.
I found this thread where someone was also having a hard time using matplotlib on a pixelbook.
The solution proposed there was to install spyder, so I did, like this:
sudo pip3 install -U spyder
This didn't help either.
It seems to me that matplotlib cannot find the graphics back end on my machine. I am running crouton and as I mentioned before gvim installed just fine. This is after the google announcement of support of linux native apps on chromebooks, so I am not running in a VM, this is stock chrome os moved to dev branch and switched to enable linux.
I am wondering if I need additional X11 backend installed separately, but I checked google documentation for installing Android Studio on Pixelbook, and it didn't mention any additional graphics installations, just "enable linux and install the linux tgz package". I would really appreciate some pointers.

Categories