Jupyter Plotting just the graph without the execution commands - python

Hi I am using jupyter notebook and every time I plot I am getting all the matplolib inline executions as per below. The graph appears at the bottom. But I would like to get only the graph as I would like to use it for presenting.
I tried the below
%matplotlib inline
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
but it doesn't work always

Are you working on python 3?
If yes add
%matplotlib notebook

Related

Problem with the display of the heatmap on jupyter: it crushes the old graphs of other measures

when I display the distributtion plot it works just fine and I get my graph displayed.
sns.distplot(df['Price'])
when I add a new code line to display the heatmap of the corr:
sns.heatmap(df.corr())
it Crushes my old graph and get displayed at its place.
can't get both graphs displayed at the same time.
You can try displaying multiple images in Jupyter notebooks with the IPython.display.display() method. IPython is the python shell used by Jupyter notebooks, so you can import it without installing any external libraries. Just wrap your plots inside the function like you would with a print method:
from IPython.display import display
display(sns.distplot(df['Price']))
display(sns.heatmap(df.corr()))

Jupyter and %matplotlib inline lost axis

I am having a really weird issue with using the %matplotlib inline code in my jupyter notebook for plotting graphs using both pyplot and the pandas plotting function.
The problem is they show up without any axes, and basically just show the graph area without anything aside from data points.
I found adding:
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
reverse it, but I find it odd that should do that every time as the effect disappears as soon as I run %matplotlib inlinecommand.
an example could be
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(A,A)
plt.tight_layout()
plt.xlabel('here')
plt.show()
This would generate the graph below:
Weird enough if I uses the savefig it get plotted with the axis, if I uses the right-click -> new output -> save as figure, I also get the graph with the figures !!
like this:
Can anyone help me understand what is wrong, which global setting did I mess up, and how do I revert it?
(I don't remember messing around with any settings aside from some settings for pandas, but don't think they should have had an impact)
as mentioned running mpl.rcParams.update(mpl.rcParamsDefault) command does bring it back to normal until I run %matplotlib inline` again !!
Any help would be much appreciated.
Okay I am sorry I think I can answer the question myself now.
With the helpfull #Mr. T asking for the imgur link made me realize what was going on. I had starting using the dark jupyter lab theme, and the graph would generate plots with transparent background, ie. the text and lines where there, but I just couldn't see them.
The trick is to change the background color preferably globally, but that will be a task for tomorrow.

How do I set matplotlib's DPI for every cell in Jupyter

When I try to set the DPI for Matplotlib plots in Jupyter, it appears to be reset in every cell:
The code:
# In[1]:
get_ipython().run_line_magic('matplotlib', 'inline')
from matplotlib import pyplot
print(pyplot.rcParams['figure.dpi'])
pyplot.rcParams['figure.dpi'] = 150
print(pyplot.rcParams['figure.dpi'])
# In[2]:
print(pyplot.rcParams['figure.dpi'])
How do I set a consistent DPI for plots throughout the entire notebook?
This is using Jupyter 1.0.0, Matplotlib 3.0.1, Python 3.6 on Windows 10.
That's a bug[*] in IPython. To work around that use the first cell of your notebook to set the backend. Manipulate the rcParams in subsequent cells.
[*] See:
ipython/ipython#11098
matplotlib/matplotlib#11693
matplotlib/matplotlib#11393
matplotlib/matplotlib#11815
jupyter/notebook#3385
Let me quote here a comment by #takluyver:
There's a bit of setup that happens just after the cell where %matplotlib inline is called, I think. So if you set things in that cell, they can be overridden by IPython's setup. After that, things you change should (I hope) be kept between cells.

Matplotlib, Jupyter: Have annotation appearing when hovering over plot

I am trying to create a plot with matplotlib that has tooltip appearing when hovering hover certain elements of the charts. I want to do that in the Jupyter Notebook, with python 3.
I have tried the snippets provided here:
http://matplotlib.org/examples/event_handling/pick_event_demo.html
Possible to make labels appear when hovering over a point in matplotlib?
Is there a matplotlib equivalent of MATLAB's datacursormode?
Matplotlib basemap: Popup box
But none of them work. The plot shows but is not interactive.
I tried with and without the magic %matplotlib inline with no effect.
I of course also modified the print statement when it was without parenthesis.
Is there a specific command or backend to use in order to have the interaction working in Jupyter?
EDIT:
the example working with mpld3 "works" but i would rather stick to the basic matplotlib.
I think you want %matplotlib notebook. This will integrate interactive plots in the notebook.

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