I have this issue after selecting the zoom button on the interactive toolbar beneath the plot. When I click to draw a rectangle (for zooming in to), black lines appears. This only happens in the bottom and right-most side of the plot.
I am using Python 3.6.4 and the following packages:
matplotlib (2.1.2)
jupyter (1.0.0)
Code to reproduce issue (within jupyter notebook):
import numpy as np
from numpy.random import random
import matplotlib.pyplot as plt
%matplotlib notebook
plt.plot(random(100), random(100), '.')
Related
I'm trying to generate some matplotlib figures, but I'm running into issues visualizing the x/y tick labels.
import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.linspace(0, 10), np.linspace(0, 10))
This problem only occurs within a jupyter notebook - I'm able to get this working in the ipython console so I'm wondering if there is a jupyter misconfiguration).
matplotlib : 3.2.2
numpy : 1.18.1
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.3
ipython : 7.13.0
ipykernel : 5.2.1
jupyter client : 6.1.3
jupyter lab : not installed
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.6
traitlets : 4.3.3
EDIT: If I can get a workaround by using seaborn to load another style via seaborn.set()
It's curious how this got overloaded in the first place.
Jupyter simply returns the Matplotlib figure, so I doubt that it would be a Jupyter misconfig.
However, what you could try doing is plt.xticks and plt.yticks which manually add the ticks in. You pass one parameter, which is an array of the ticks that you want to display. In this case you would pass it like this:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(np.linspace(0, 10), np.linspace(0, 10))
plt.xticks(np.arange(0, 10, 1)) # Here np.arange() generates a sequence of number starting from 0 and ending at 10, going up in increments of 1.
plt.yticks(np.arange(0, 10, 1)) # Same for the y axis
plt.show()
Two points of note here. Firstly, the %matplotlib inline in line 3 is only necessary for when you are in a Jupyter environment, as this is a special signal to the Jupyter kernel to display any plots inside the notebook.
Also, it is probably good practice to have plt.show() at the end, because if, in some case, you are not working in a Jupyter environment, the code will not return the plot unless you call this function. Jupyter is nice and extracts the plot, but just as good practice, use this line of code at the end.
Hi everyone. I am running jupyter notebook through Chrome and Windows
10. the versions are : Windows 10 Chrome Version 84.0.4147.105 (Official Build) (64-bit) I am using the magic %matplotlib notebook.
To be able to zoom in and out in the plot. The code works in other
machines with same windows and version. However, when I run it in my
personal laptop, the plot is not possible to see it:
I was trying to follow the following info found: help
I have run out of ideas, I restarted the laptop, reinstalled jupyter,
and nothing seems to work. Did anyone have a similar issue? Here is the code:
%matplotlib notebook
import matplotlib.pyplot as plt
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import numpy as np
import pandas as pd
def g(qi,d):
fig = plt.figure()
x_1 = df['dprod_year']
y_1 = qi*np.exp(-x_1*d)
plt.scatter(x_1,y_1,marker='+')
plt.scatter(df['dprod_year'],df['qoil_1000b'],marker='o',color='grey')
plt.ylim(0,4000)
plt.xlim(0,60)
plt.grid(True,axis='both')
"""
#interact(g,qi=(0.0000,5000,10),d=(0.0000,0.02000,0.0010))
"""
interact(g,qi=widgets.FloatSlider(value=3900,min=0,max=4000,step=10,description='qi:',readout_format='.1f'),
d=widgets.FloatSlider(value=0.0061,min=0.0001,max=0.01,step=0.001,description='d:',readout_format='.5f'))
plt.show()
Thank you very much for your help.
You should try to change from %matplotlib notebook to %matplotlib inline.
If that doesn't work then try to restart the kernel.
It seems that in some cases it helps to repeat the setting of the notebook backend, i.e. try calling it twice like
%matplotlib notebook
%matplotlib notebook
An analysis for why that is can be found in this comment
I run this script in a Jupyter notebook:
import matplotlib.pyplot as plt
plt.plot(range(10))
I get a nice plot as an output. I run this debug.py from terminal:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
./debug.py doesn't give a plot. My cursor changes shape, it becomes a cross pointer, but I don't get any plot, and I don't get back my terminal prompt.
Following the recommendation given in this answer, I run in a local python3 shell this:
>>> import matplotlib
>>> print(matplotlib.rcParams['backend'])
The output is TkAgg, as it should be, based on the answer to the aforementioned question.
Why I don't get a matplotlib window then?
I am trying to use matplotlib to view an image in ipython. However, I solely obtain a description of the image as opposed to seeing the actual image:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> plt.imshow(an_array)
Out[4]: <matplotlib.image.AxesImage at 0x7fb626f063d0>
This is with the backend set to Qt5Agg or TkAgg in .matplotlibrc
I have the same issues whether or not I am working in a conda virtual environment
I am running: Scientific Linux release 6.8 (Carbon), Python 2.7.13, Anaconda 4.3.0 (64-bit)
I have had similar issues on my local computer running MacOSX
I would be most grateful for any advice,
Thanks
Rob
Add %matplotlib inline before import matplotlib.pyplot as plt to enable automatic visualization of your plots when the cell has finished executing.
Note, however, that this works just in iPython notebooks. Normally, you'd need to call plt.show() (without any arguments) to visualize the plots.
I just started to use Jupiter Notebook to learn Python. while I am trying out matplotlib with this basic code:
import numpy as np
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
The kernel just keep running and nothing happen. How to resolve this? Is there an dependency issue? My newly installed matplotlib is 1.5.1, python is 3.5.2, numpy is 1.11. Running on MacBook Pro 10.11(El Capitan).
To Visualize the plots created by the matplotlib in Jupiter Notebook or ipython notebook you have add one extra line at the beginning.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
If your matplotlib version is above 1.4, and you are using IPython 3.x you have to use the below code.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
It likely showed you a Matplotlib popup, with the IP(y) logo. To show it inline you have to use some IPython magic. Run this in a cell somewhere:
%matplotlib inline
After you close the popup it will finish the statement in your kernel
It sometimes takes time until the kernel starts.
Check that the code is color-highlighted. If it is, it means that the kernel is running. Evaluate the cell again. You will notice a * beside that cell, meaning it's running.
And one more thing: Sometimes the plot is displayed but its window hides behind the notebook... Access it from the task bar