简体   繁体   English

绘图窗口没有出现在matplotlib中

[英]plot window not showing up in matplotlib

I am trying to plot a graph using matplot lib and am not getting a window to show up: 我正在尝试使用matplot lib绘制图形,并且没有显示一个窗口:

I got this snippet of code from a demo program for contours using matplotlib. 我从使用matplotlib的轮廓演示程序中获得了这段代码。

import matplotlib
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)



# Create a simple contour plot with labels using default colors.  The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
plt.figure()
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')

plt.show()

Now I expect plt.show() to show a plot but alas when I run the program I do not see a plot but instead get an error message saying: 现在我希望plt.show()显示一个情节,但是当我运行程序时,我没有看到情节,而是收到一条错误信息:

import: unable to grab mouse `': Resource temporarily unavailable @        error/xwindow.c/XSelectWindow/9047.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9047.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9047.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9047.
./plotter.py: line 7: matplotlib.rcParams[xtick.direction]: command not found
./plotter.py: line 8: matplotlib.rcParams[ytick.direction]: command not found
./plotter.py: line 10: delta: command not found
./plotter.py: line 11: syntax error near unexpected token `('
./plotter.py: line 11: `x = np.arange(-3.0, 3.0, delta)'

Any idea on how to resolve this issue? 有关如何解决此问题的任何想法?

Thank you for your time. 感谢您的时间。

The code is fine, your have executed it as a shell script if I am not mistaken. 代码很好,如果我没弄错的话你已经把它作为shell脚本执行了。 You should execute it with the python interpeter. 你应该用python interpeter执行它。

Oper a terminal and run python script-name.py 操作终端并运行python script-name.py

If you have matplotlib and numpy installed you should be fine. 如果您安装了matplotlib和numpy,那么您应该没问题。

matplotlib is tricky in the standard python interpreter. matplotlib在标准的python解释器中很棘手。 ipython has better integration with matplotlib, so you might want to try using that instead of the standard python command line interpreter. ipython与matplotlib有更好的集成,所以你可能想尝试使用它而不是标准的python命令行解释器。 It'll make your life easier on so many fronts. 它会让你的生活在这么多方面变得更轻松。

ipython IPython中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM