Matplotlib does not show up on ubuntu windows subsystem - python

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/

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.

UserWarning: Matplotlib is currently using agg, so cannot show the figure

I'm trying to run a basic matplotlib example from the official website:
However, when i run the code, my Python interpreter complains and outputs the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
I've installed matplotlib via pip3 install matplotlib.
My current python3 version is 3.9.1 and my OS is Ubuntu 20.04.
I've already tried installing tkinter, as already described here, with no success.
What should I do? Why is this happening?
Please try these, if any works for you:
if you are using Jupyter Notebook
%matplotlib inline
make sure you have tkinter, recompile python interpreter after installing tkinter
try:
import matplotlib
import matplotlib.pyplot as plt
plt.style.use('ggplot')
matplotlib.use( 'tkagg' )
x = [1, 5, 1.5, 4]
y = [9, 1.8, 8, 11]
plt.scatter(x,y)
plt.show()

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.

Using python on windows 7 and 10

Recently been having trouble using python on my laptop. I used to have windows 8.1 in my laptop, but saw most of my classmates use python with windows 10. So I updated to windows 10. Still having problems. I ended up using my desktop which has windows 7 and it worked perfectly. The problems have been when I would try and plot graphs or when id use arange. My question is, does windows really play a factor on python? they both have python version 3.5.1 python build 4 and 144 installed packages.
from numpy import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import *
from pylab import *
import pylab as pl
from matplotlib.pyplot import *
from math import exp, expm1
from __future__ import division
%matplotlib inline
There is nothing to do with windows. Either way you can uninstall python and reinstall it,may resolve your problem. But make sure you have installed numpy as well.You can get package for that http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy . Python installation has nothing to do with your windows version.

pyplot while using X11 forwarding

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()

Categories