12

I am trying to create a 2x2 plots for Anscombe data-set

Loading Data-set and separating each class in data-set

import seaborn as sns
import matplotlib.pyplot as plt

anscombe = sns.load_dataset('anscombe')

dataset_1 = anscombe[anscombe['dataset'] == 'I']
dataset_2 = anscombe[anscombe['dataset'] == 'II']
dataset_3 = anscombe[anscombe['dataset'] == 'III']
dataset_4 = anscombe[anscombe['dataset'] == 'IV']

Creating a figure and dividing into 4 parts

fig = plt.figure()

axes_1 = fig.add_subplot(2,2,1)
axes_2 = fig.add_subplot(2,2,2)
axes_3 = fig.add_subplot(2,2,3)
axes_4 = fig.add_subplot(2,2,4)

axes_1.plot(dataset_1['x'], dataset_1['y'], 'o')
axes_2.plot(dataset_2['x'], dataset_2['y'], 'o')
axes_3.plot(dataset_3['x'], dataset_3['y'], 'o')
axes_4.plot(dataset_4['x'], dataset_4['y'], 'o')

axes_1.set_title('dataset_1')
axes_2.set_title('dataset_2')
axes_3.set_title('dataset_3')
axes_4.set_title('dataset_4')

fig.suptitle('Anscombe Data')

fig.tight_layout()

The only output which i'm getting at each plot is

[<matplotlib.lines.Line2D at 0x24592c94bc8>]

What am I doing wrong?

4
  • 2
    This issue isn't reproducible. I can get your plots with exactly what you have. conda update conda and conda update --all at the conda prompt. Also, instead of jupyter notebook, type jupyter lab at the prompt. This is the newer version of jupyter and is already part of the distribution. Commented Apr 9, 2020 at 18:58
  • OK..i'm trying. Commented Apr 9, 2020 at 19:05
  • Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure. """Entry point for launching an IPython kernel Commented Apr 9, 2020 at 19:32
  • stackoverflow.com/questions/37365357/… Commented Apr 9, 2020 at 20:16

4 Answers 4

20

If you are working with a Jupyter Notebook then you can add the following line to the top cell where you call all your imports. The following command will render your graph

%matplotlib inline

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

let me try in my environment
Try using a colab notebook colab.research.google.com/notebooks
Could you please share your code...I tried it in colab as well..not working
Getting this warning:- Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure. """Entry point for launching an IPython kernel.
2

Add%matplotlib inline or use matplotlib.pyplot.ion()

after you imported matplotlib.

From plotting docs:

Starting with IPython 5.0 and matplotlib 2.0 you can avoid the use of IPython’s specific magic and use matplotlib.pyplot.ion()/matplotlib.pyplot.ioff() which have the advantages of working outside of IPython as well.

9 Comments

restart your kernel and see if that fixed the issue . you can also remove the inline part and see if it shows up in a new window
Tried both still same result..no error received and plots not showing
try forcing it with plt.draw() or plt.show() and see if that helps. give %matplotlib notebook a try as well .
Not working..Could you please check the same code in your environment and check if it is working for you
just asking, you are not by any chance using the vscode ipython interactive mode are you? if you are, vscode has its own share of issues, please use Jupyter notebook. if you are using jupyter notebook, try updating it both the jupyter itself and notebook.
|
1

I've tried all of the above, eventually I've found out there is a conflict between matplotlib and a library called dtale. When I removed the import dtale command and restarted the kernel all was working prefectly good.

Comments

0
%matplot plt

Executing this after plt.show() displayed the plots for me.
Found this here: How do I make matplotlib work in AWS EMR Jupyter notebook?

1 Comment

this solved my issue, the other answers did not. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.