matplotlib doesn't plot in terminal - python

I am trying to plot some scientific data by using Matplotlib in terminal.
here is my simple code :
import matplotlib.pyplot as plt
plt.plot([1,2,3],[3,2,5])
plt.show(block=True)
But I can't see any graph on my linux.
I am using wsl on windows for linux.
debian is my linux.
The link below doesn't help my problem:
Matplotlib plots aren't shown when running file from bash terminal
as you see I set block to True and nothing! for now I am using plt.savefig() function to see my result in windows.
may be I need to install some software in my Linux for image viewer , no?
thank you

Related

Cannot get matplotlib graphics to show up inline

I would like to load automatically the command lines with Jupyter in Ubuntu 16.10 :
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
With Ubuntu, we could normally use configuration files as .vimrc, .bashrc and so on to automate some command lines. I know we could create the config file jupyter_notebook_config.py with jupyter notebook --generate-config. How could we implement that in python in that .py file?
Thanks!
You can't have graphics inline in a regular terminal because regular terminals don't have graphics capabilities. However, if you would be willing to use an alternative console, Jupyter Qtconsole, may be suitable for you.
EDIT: okay, I've had a look and you need to look at this, specifically the parts about running files/lines of code at startup. (like c.InteractiveShellApp.exec_lines or c.InteractiveShellApp.exec_files

Matplotlib is hanging when using python3

Matplotlib hangs now that I've upgraded to Sierra.
The behavior is different depending on how I run it.
In a file (running with %run <filename> inside of ipython or python <file name> from the terminal):
The terminal will hang on import (import matplotlib.pyplot as plt) and all I get is the little rocket icon bouncing in my dock.
Directly from ipython:
I can import it and show a plot, but it will hang once I try to close the figure window. Doing this from inside of the basic python shell does not have this problem. So it seems running in interactive mode also causes hanging.
Has anyone experienced something similar?
python version: 3.5.2
matplotlib version: 1.5.1
backend: MacOSX
OSX: 10.12.2
Switching to a TkAgg backend will display the figure window, but it will hang on plotting (in interactive mode).
Note
Setting up a virtual environment to run python 2.7 with a TkAgg backend works as expected
Seems to be a caching issue:
running:
cd ~/.matplotlib
fc-list
fixed the problem (same issue discussed here: import matplotlib.pyplot hangs but the symptoms were a little different)

matplotlib interactive… isn't

I'm running Python 3.5.1 with matplotlib version 1.5.1 and iPython 5.0.0. I can't seem to get matplotlib's interactive feature working. I can run a command to create a plot:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3])
This doesn't show a figure until I manually execute plt.show(), at which point iPython hangs until I close the figure window. I have interactive set to True in my matplotlibrc file.
It's been a year or so since I used matplotlib. The last time I used it, I got interactive without having to execute plt.show(). Has something changed or am I doing something wrong?
You were probably using interactive mode previously.
Start ipython with:
ipython --pylab
Then your plots will show up instantly.

Plot cannot opened in python laucher in Mac

I'm following the Pyplot tutorial and I wanted to create a plot in Python IDLE 2.7.10 Shell. During the code execution, the python launcher has been called. However, the launcher just 'jump' and 'jump' again, but it connot open to show the plot.
Code
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
Environment
Mac OSX version : 10.10.5
Python version : 2.7.10
If you want to display it, add plt.show()

Plot plotted inside the ipython console

I am working in python and using Anaconda with Spyder and I need to plot a scatter plot in a part of the code I am working on. The plot is just fine but is drawn in the console itself and the size is quite small for my needs.
My question is, how can I plot it in another window outside the ipython console? I already tried changing some of the setting like changing Graphics setting in ipython from inline to QT to tkinter. Nothing seems to work.
Any helpful suggestions?
you can just save %matplotlib qt in a .py file and you can start ipython using:
ipython -i myfile.py

Categories

Resources