How can I open plot viewer in vs code jupyter? - python

I am using python to plot in VS code Jupiter on my Mac. The plot is shown in the Interactive View, while I cannot do more thing like zoom or save in the view. I refer to Python Interactive window(see Plot Viewer)and it says:
Within the Python Interactive window, double-click any plot to open it in the viewer, or select the expand button on the upper left corner of the plot.
Expand Button
Plot Viewer
The expand button is supposed to be shown and open the Plot Viewer, while I don't have the button and there is nothing happen after I double-click the plot.
No Button Shows
My test code:
import seaborn as sns
import numpy as np
x = np.random.randn(100)
ax = sns.distplot(x)
Could you please help with my issue? I wonder whether I miss any extension. Thank you very much!

If still does not work please check the version of the Python and Jupyter extensions.

Default the renderer used in Interactive Python windows uses the PNG renderer.
You can change it to use the TkAgg renderer (external window)
Add %matplotlib to the script
%matplotlib
import seaborn as sns
import numpy as np
x = np.random.randn(100)
ax = sns.distplot(x)
You can use other plot renderers

Related

How to get good plots in Spyder python ? (Inline and Qt5)

When i plot in Spyder with the Backend Qt5 in graphics ( the window that pops with the plot) i don't get things aesthetically beautiful. The title sometimes is not showing, the labels, ... All in all it is just not good looking. But when it is plotted "inline" it is very well presented.
What I want is :
I want the plot with the Backend Qt5 option very well presented like the Backend Inline option.
The code is this :
import numpy as np
from matplotlib import pyplot as plt
plt.plot(np.linspace(0,2, num = 5))
plt.title('Blabla')
plt.xlabel('Anything')
plt.ylabel('Everything')
What I get with the Backend Qt5 option
What I get with the Backend Inline option
I think the command %matplotlib qt might be the solution to this problem. You should write the line in the IPython Console.
The problem was the use of this line in order to increase the quality of the plots:
plt.rcParams['figure.dpi'] = 300
In Qt5 it's not required.

%matplotlib notebook shows blank icons in Jupyter notebook

I'm trying to create a simple interactive plot with sliders and matplotlib in Jupyter, however, the icons are simply showing a blank square instead? Figure below:
Blank icons using notebook backend
Am I missing a dependency? I believe I'm using default settings for everything.
A simplified version of my code is shown below:
%matplotlib notebook
import matplotlib.pyplot as plt
from ipywidgets import FloatSlider, interact
fig = plt.figure(figsize=(10,3))
ax = fig.add_subplot(1, 1, 1)
ax.set_xlabel('time [s]')
ax.set_ylabel('displacement [cm]')
x1, = ax.plot(t,x)
def update(P_l = FloatSlider(min=0,max=4000,step=50,value=1500)):
x1.set_ydata(x)
fig.canvas.draw()
interact(update)
Thanks in advance!
Jupyter Notebook tends to minimize heavy graphs and tables when it exceeds a specific size. Not sure about the accurate answer, But did you try double clicking the left edge of graph? It does the job in my windows PC.

How to get interactive plot of pyplot when using pycharm

I am using PyCharm as the IDE for python, and when you make a plot (with the same code like pyplot.plot(...), pyplot.show()) pycharm displays it within its IDE. However, this looks like a static image. When you zoom in, the plot starts to blur.
In other IDE, pyplot creates an interactive plot. When you zoom in, it basically re-plots the curve. And you can also drag the plot. Is there anyway in PyCharm I can have the interactive plot from pyplot?
Just need to change your plotting backend.
If you're on macOS:
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use('macosx')
plt.plot(range(10))
should produce a new window that looks like this:
Or if you prefer a different backend or are on Windows (as #MichaelA said)
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use('Qt5Agg') # or can use 'TkAgg', whatever you have/prefer
plt.plot(range(10))

matplotlib windows 10 old looking plot window

I have python 2.7.14 on Win10, and installed matplotlib 2.1.2 via pip. I don't like the way the buttons and the whole plot window look like. How can I fix this. It should rather look like in 1.
supposed to be plot window
my plot window
As of matplotlib version >= 2.0 using
import matplotlib.pyplot as plt
plt.gca()
plt.show()
you get this window now:
You can use the classic style (plt.style.use("classic")) to get the old figure style back:
import matplotlib.pyplot as plt
plt.style.use("classic")
plt.gca()
plt.show()
The buttons however are now still different.
In order to change the buttons, you could locate the folder with the buttons,
<path to python>\Lib\site-packages\matplotlib\mpl-data\images
and replace the images in it with the images of your choice. E.g. you might want to download an older matplotlib version and take the images from there.

Matplotlib in python on a mac opens a new window

I am new to the world of mac. In python we I want to visualize a data, I use matplotlib's pyplot to generate a plot but when I do pyplot.show() it creates a new window. This behavior also happens inside my ipython notebook too - see image below. I wanted it to embed the image inside the notebook.
How can I correct this ?
Try ipython notebook --pylab inline when you launch ipython.
Input in a cell, the cell magic %pylab inline or %matplotlib inline will make the plots appear inline/interactive (instead of a new window).
Not that if you use %matplotlib cell magic, you still need import matplotlib.pyplot as plt and import numpy as np etc. With %pylab cell magic you don't.

Categories

Resources