I run this script in a Jupyter notebook:
import matplotlib.pyplot as plt
plt.plot(range(10))
I get a nice plot as an output. I run this debug.py from terminal:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
./debug.py doesn't give a plot. My cursor changes shape, it becomes a cross pointer, but I don't get any plot, and I don't get back my terminal prompt.
Following the recommendation given in this answer, I run in a local python3 shell this:
>>> import matplotlib
>>> print(matplotlib.rcParams['backend'])
The output is TkAgg, as it should be, based on the answer to the aforementioned question.
Why I don't get a matplotlib window then?
Related
I'm working on a project that creates some graphics using matplotlib in pydroid but I need to see some output in the terminal but when I import matplotlib and run the code it shows the matplotlib GUI window and not the pydroid terminal how can I solve that?
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("/file.csv")
print(df)
It looks like Pydroid 3 (version 5.00_arm) is sensitive to the phrase import matplotlib .
For example , if you run this code:
#import matplotlib
print(3+3)
you won't see any result.
If you want to see the terminal output , first run your code and then use Graphical program output as shown below:
I have this issue after selecting the zoom button on the interactive toolbar beneath the plot. When I click to draw a rectangle (for zooming in to), black lines appears. This only happens in the bottom and right-most side of the plot.
I am using Python 3.6.4 and the following packages:
matplotlib (2.1.2)
jupyter (1.0.0)
Code to reproduce issue (within jupyter notebook):
import numpy as np
from numpy.random import random
import matplotlib.pyplot as plt
%matplotlib notebook
plt.plot(random(100), random(100), '.')
I just started to use Jupiter Notebook to learn Python. while I am trying out matplotlib with this basic code:
import numpy as np
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
The kernel just keep running and nothing happen. How to resolve this? Is there an dependency issue? My newly installed matplotlib is 1.5.1, python is 3.5.2, numpy is 1.11. Running on MacBook Pro 10.11(El Capitan).
To Visualize the plots created by the matplotlib in Jupiter Notebook or ipython notebook you have add one extra line at the beginning.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
If your matplotlib version is above 1.4, and you are using IPython 3.x you have to use the below code.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
It likely showed you a Matplotlib popup, with the IP(y) logo. To show it inline you have to use some IPython magic. Run this in a cell somewhere:
%matplotlib inline
After you close the popup it will finish the statement in your kernel
It sometimes takes time until the kernel starts.
Check that the code is color-highlighted. If it is, it means that the kernel is running. Evaluate the cell again. You will notice a * beside that cell, meaning it's running.
And one more thing: Sometimes the plot is displayed but its window hides behind the notebook... Access it from the task bar
I am using
%matplotlib inline
to display plots inside the notebook. I would like to disable this for several cells. So, I try
%matplotlib qt
This outputs the following error:
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
or PySide package to be installed, but it was not found.
I am not sure how to solve this, as everything is up to date.
How can I solve the above?
Is there another way to disable %matplotlib inline in a certain cell without restarting the entire kernel?
You might be able to use plt.switch_backend, although as the documentation states, this is an experimental feature. The following works for me, using matplotlib 1.5 and an IPython 4.0.1:
In [1]: from matplotlib import pyplot as plt
In [2]: import numpy as np
# plot appears inline (default)
In [3]:plt.plot(np.random.randn(10))
Out[3]:[<matplotlib.lines.Line2D at 0x7fac4408e390>]
In [4]: plt.switch_backend('QtAgg4')
# plot appears inside a separate Qt4 window
In [5]:plt.plot(np.random.randn(10))
Out[5]:[<matplotlib.lines.Line2D at 0x7fac3b408a90>]
You might need to change 'QtAgg4' according to whichever version of PyQt you have installed - this could be the cause of the error you mentioned in the question. Another interactive backend that should work on Mac would be 'CocoaAgg'. If the images are very large you could also use the 'Agg' backend to suppress plotting altogether, and instead save the resulting figure(s) straight to disk.
If you don't have a specific backend installed use "agg":
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
Reference: https://github.com/matplotlib/matplotlib/issues/9017
I'm working on a program in python with packages numpy,scipy and matplotlib.pyplot. This is my code:
import matplotlib.pyplot as plt
from scipy import misc
im=misc.imread("photosAfterAverage/exampleAfterAverage1.jpg")
plt.imshow(im, cmap=plt.cm.gray)
for some reason the image isn't showing up (checked if I got the image, in that part it's all fine- I can print the array.).
You need to call plt.show() to display the image. Or use ipython --pylab for an interactive shell that is matplotlib aware.
"Interactive mode may also be turned on via matplotlib.pyplot.ion(), and turned off via matplotlib.pyplot.ioff()" cf. matplotlib user guide.