Matplotlib plt.show()方法不会弹出窗口 [英] Matplotlib plt.show() method does not pop out the window

查看:115
本文介绍了Matplotlib plt.show()方法不会弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 matplotlib 的 plt.show() 方法有一些问题.当我运行以下代码时,绘图显示在 IPython 控制台内.我在 Python 3.5 中使用 Anaconda

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 如下.

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

我还粘贴了 matplotlibrc 文件内容此处

控制台上的 plt.get_backend()命令提供

'module://ipykernel.pylab.backend_inline'

'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

推荐答案

在Spyder中,单击工具",首选项","Ipython控制台",图形".在图形下,将后端更改为自动"而不是内联".

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

这篇关于Matplotlib plt.show()方法不会弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆