Cannot display inline chart in IPython notebook - matplotlib

I've seen the exact same question around but the answers didn't help me. like those questions:
Cannot show the graphs on ipython notebook
How to make IPython notebook matplotlib plot inline
So I decided to post a question so i could post my code, see if there is anything different... hopefully it's something very dull that I'm missing. although the code runs perfectly in ipython shell. Thanks in advance !
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp')
plt.show()
PS: I'm using Anaconda distribution, and I launched notebook by the shortcut that comes with it IPython (Python 2.7) Notebook
PS2: the output I get is virtually none.

Related

Jupyterlab kernel remains busy with matplotlib widget

I'm new to Jupyterlab and matplotlib so this may be a dumb question but here goes.
FYI: I'm using the standalone jupyterlab app on a mac.
When I make a simple interactive plot using the matplotlib widget magic, the kernel stays busy forever. I had found an earlier post on stack overflow about putting the magic in the 2nd cell (why this works?) and the plot works fine, I just want to know what's going on with the kernel.
The code, which works fine, is just:
import numpy as np
%matplotlib widget
import matplotlib.pyplot as plt
x = np.arange(10)
y = 2*x
plt.figure()
plt.scatter(x,y)
A screenshot to illustrate.
Kernel stuck running in top right of shot
UPDATE: To be clear, this is occurring on the Jupyterlab Standalone app. If I run this on jupyterlab launched via the anaconda navigator, it works fine. For whatever reason, it seems confined to the standalone app only.
As for the App, I installed it via the binary at GitHub. I'm running 3.3.2-2

Matplotlib zoom in/out feature in Jupyer notebook without installing packages

please I'm working from my office and I have here Anaconda installed on my machine. I have different dataframes that I plot using matplotlib (see example below). I would need the ability to zoom in/out with the mouse without installing gtk or plotly or any additional library.
Is there any simple way to add this feature?
Many thanks
import numpy as np
from numpy.random import randn
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.DataFrame(randn(50,4),columns='W X Y Z'.split())
df["X"].plot()
plt.show()
Replace %maptlotlib inline with %matplotlib notebook.
Now you have an interactive figure in your notebook.

pop-up plots using Python Jupyter Notebook

Is there a way to have the plots created inside Jupyter Notebook using matplotlib to appear on a separate pop-up screen that would allow you to expand/shrink the image by hand? I've tried experimenting with (%matplotlib notebook) but that didn't really do the trick.
Just wondering if this is possible.
Just use an interactive backend. This works for me:
import matplotlib.pyplot as plt
%matplotlib tk
plt.plot([1, 2])
The notebook (nbagg) backend also allows for expand/shrink by hand. It has some rough edges though.
The tkinter backend is a bit buggy (windows 10, python 3).
I used %matplotlib qt for the matplotlib plot that we are all used to.

jupyter notebook + seaborn + %matplotlib notebook -> grid not visible

If I try to use in a jupyter notebook
%matplotlib notebook
import seaborn as sns
...
plt.grid()
The the grid is not visible.
If I try the same in plain python (not jupyter notebook, without %matplotlib), the grid is fine.
Calling plt.grid() with no arguments toggles the grid state. Because there is a grid in the default seaborn style, you are turning it off.

I don't know how to make a new matplotlib figure

I'm using Jupyter notebook with %matplotlib notebook in one of the first lines.
When making multiple plots, I have to physically press the 'stop interaction' button on each figure before running another plot, or else the newest plot will be overlaid onto the previous figure.
I think the problem is that I'm not specifying that a new figure needs to be made for each plot? But I'm stumped as to how best to do that!
DO I REALLY HAVE TO SAY PLT.FIGURE EVERY SINGLE TIME? THIS SEEMS UNLIKELY TO ME...?
Thanks in advance!
This is a bug with the notebook backend, but luckily the person who reported it also reported a workaround
Within the Notebook you will need to add the plt.ioff after you import pyplot.
Here is a snip from the top of a notebook, that makes it work for me. I was getting plots over written like you.
%matplotlib notebook # this is to allow the plotting in the notebook
import numpy as np
from scipy.linalg import hadamard
import matplotlib.pyplot as plt
plt.ioff() # this stops the graphs from overwriting each other