Why the plots look blurry with "TkAgg" backend on retina screen? - python

I'm using matplotlib to show plots in a GUI app done with tkinter. I've noticed that plots look blurry on the retina screen of my Mac Book Pro.
Below is a minimal example to reproduce my problem. Why am I having the blurry plots with "TkAgg" backend? Is there a way to fix this?
MacOS 10.13.2, Python version: 3.6.4, Matplotlib version: 2.1.2, tkinter.TkVersion: 8.5.
Notice that the default "MacOSX" backend produces nice sharp plots. Besides, if I create a tkinter app, other elements like labels, menus are sharp as well, only the plot is blurry.
import matplotlib
matplotlib.use('TkAgg') # Remove this to compare with MacOSX backend
import matplotlib.pyplot as plt
f = plt.figure(figsize=(6, 4))
a = f.add_subplot(111)
a.plot([1,2,3,4])
plt.show()

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.

How can I open plot viewer in vs code jupyter?

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

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.

Axes missing when plotting in matplotlib using vispy as backend

I have been watching the development of the python graphing library vispy with excitement. I just discovered that I can use vispy as a backend to matplotlib, which is great because I am plotting hundreds of thousands of points. I ran the example and I noticed there are no axes. I also ran the following code.
import vispy.mpl_plot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.show()
The axes were present until the plt.show() command, and they disappeared. I understand that the vispy project is under development, but plotting with axes would be extremely valuable to me, so I was wondering how I could do this. Also, less urgently, the border around the graph becomes huge. Is there a way to shrink the border?
The support for the matplotlib backend was dropped in version 0.5:
https://github.com/vispy/vispy/pull/1224

Categories

Resources