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

user9026
  • 852
  • 2
  • 9
  • 20

2 Answers2

5

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

pyan
  • 3,577
  • 4
  • 23
  • 36
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
    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. – 404pio Nov 15 '19 at 17:35