Any help with the issue is appreciated. As the following photo shows, I am trying to get an horizontal bar chart and always get instead. I don't know what to do with it.
Reposting as an answer:
If you run the %matplotlib magic in IPython before creating plots, the plots will appear automatically, and won't block the prompt.
We're working with matplotlib so that this won't be necessary in matplotlib 2.0.
Related
I am trying to embed a already made matplotlib figure and want to embed that figure in my tkinter window without a separate pop up window.
can you please help if there is a way to display matplotlib objects in tkinter without using the plot() command?
any help would be highly appreciated
thanks..
When I create a matplotlib chart in my jupyter notebook in vscode, it gives the whole cell a white background. I've tried putting
"import matplotlib.pyplot as plt",
"plt.style.use('dark_background')"
in my settings file to run as startup commands and that makes it gives the plot a black background, but it still doesn't match my vscode theme. Does anyone know how to make them match seamlessly? transparent chart background mabye?
The white background is actually on purpose so that it matches what Jupyter would show. It's from reading the 'needs_background' element of the matplotlib output.
The background unfortunately will always be either white or black based on the 'needs_background' element. (As you found with your style of 'dark_background')
The code for that is here:
https://github.com/microsoft/vscode-notebook-renderers/blob/91210f63be0fcca92d7ea9125b7e9445a423b0a4/src/client/render.tsx#L70
You can enter a request for the jupyter extension to change that color here:
https://github.com/microsoft/vscode-jupyter/issues
You can plot your chart in a PyQt5 window.
I am not sure if this solves your problem, but it's a way to make the chart transparent. I hope it's helpful:
You need to import PyQt5 (pip3 install PyQt5).
from PyQt5 import QtCore
The code to create the transparent window is inserted after defining your figure:
window = plt.gcf().canvas.manager.window # used to get your figure
window.setAttribute(QtCore.Qt.WA_NoSystemBackground, True)
window.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
window.setStyleSheet("background:transparent")
Finally show the window with plot.show():
plt.show()
Plot on VS Code jupyter notebook takes all the width on cell output. Before June update this wasn't a problem. Problem is on dark theme it creates too much unnecessary white space. Does anyone know the reason?
you can "fix" it for your current notebook session by resetting matplotlib option back to default .
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
If you check on the vs code notebook docs, you can see the same white space appears in their screenshots.
Within a Jupyter Notebook, why is it necessary to include this line:
%matplotlib inline
This seems to be required for matplotlib to work.
It is not necessary to include the line %matplotlib inline in a jupyter notebook.
Introducing this line selects the backend for matplotlib plotting to be the inline backend. This simplifies a lot of things, such as showing figures. If this backend is selected, a figure will automatically appear in the output once it is meantionned in a cell.
Without having selected the %matplotlib inline backend, you would need to call plt.show() to show the matplotlib output.
matplotlib figures show up fine in Ipython3 (v 6.0.0) but won't appear in either the qtconsole 4.3.0, under python 3.4.6, or the notebook. for example, plt.plot(range(7)) does not appear
and plt.show() does not help
However, if I do %matplotlib inline then I do get the plots in both the notebook and qtconsole.
Separate figure windows used to work for me and I can't figure it out.
thanks,