2

I have some problem with matplotlib's plt.show() method. When I run the following code, the plot is displayed inside IPython console. I am using Anaconda with Python 3.5

import matplotlib.pyplot as plt
import numpy as np
import csv

x = []
y = []

with open(r"F:\my_dir\example.txt", 'r') as csvfile:
    plots = csv.reader(csvfile, delimiter = ',')
    for row in plots:
        x.append(int(row[0]))
        y.append(int(row[1]))

plt.plot(x,y, label = 'Loaded from file')

plt.xlabel("x")
plt.ylabel("y")
plt.title("This is my plot")
plt.legend()

plt.show()

example.txt is as follows.

1,3
2,6
3,1
4,8
5,9
6,2
7,9
8,5
9,4
10,17

I am also pasting the matplotlibrc file content here

The plt.get_backend() command on the console gives

'module://ipykernel.pylab.backend_inline'

I want the script to pop out the plot window. This used to happen earlier but now it has stopped. Please help

8
  • Try updating IPython and matplotlib Commented Aug 31, 2016 at 6:10
  • I installed Anaconda just over 2 weeks ago. And plt.show() used to get me pop out window till yesterday. Only today this strange behavior has started Commented Aug 31, 2016 at 6:13
  • Does it even create the plot? Try to use "savefig" and see if it fails at generating the plot or at showing it. Commented Aug 31, 2016 at 6:25
  • Philip, It does show the plot inside IPython console. I want to have pop up window for the plot. Commented Aug 31, 2016 at 6:43
  • Found answer here. type %matplotlib qt when you want graphs in a separate window and %matplotlib inline when you want an inline plot Commented Aug 31, 2016 at 7:13

2 Answers 2

5

In Spyder, click Tools, Preferences, Ipython Console, Graphics. Under Graphics, change Backend to “automatic” instead of “inline”.

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

Comments

2

Thanks pyan. This really helps.

But in addition, after following the above step, please restart your kernel to see the effect. Shortcut is "Ctrl+."

1 Comment

Hi Nishant Kumar. If someone's answer is helpfull to you, you can mark his answer as helpfull, for further users looking for similar questions. This helpfull flag is green checkbox near answer vote.

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.