matplotlib基本问题 [英] matplotlib basic question

查看:57
本文介绍了matplotlib基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在探索在离开学校时使用python作为替换

MATLAB的可能性。所以,我最近在我的Windows XP机器上安装了python

2.5.1和matplotlib 0.90之后,我一直在使用matplotlib和

遇到了一些奇怪的行为。这是一个例子
我看到的


>>>来自matplotlib.pylab import *
x = arange(-2 * pi,2 * pi,pi / 24)
y = sin(x)
plot( x,y)



[< matplotlib.lines.Line2D实例位于0x017C38C8>]


>> show()



所以,首先,在我的情节命令之后显示的是[< matplotlib.lines.Line2D实例

在0x017C38C8>]行?第二,

,当我打电话给show()时,一个新的数字弹出我的罪恶浪潮 - 似乎所有

对,是吗?但是我没有在IDLE中给出另一个>>提示符,直到或者

,除非我关闭弹出show()调用的数字。


所以,关闭图后我输入:


>>> show()
plot(x,y)



这次又是另一个数字弹出我的正弦波我也得到了

a提示。但现在,数字窗口完全没有响应 - 我甚至无法关闭它而没有得到你的

程序没有重复。商业。我错过了什么?到目前为止,这个

的行为似乎很不直观。


任何澄清都表示赞赏!


trevis

解决方案


所以,首先,关闭[< matplotlib。 lines.Line2D实例

在0x017C38C8>]行显示在我的plot命令之后?第二,

,当我打电话给show()时,一个新的数字弹出我的罪恶浪潮 - 似乎所有

对,是吗?但是我没有在IDLE中给出另一个>>提示符,直到或者

,除非我关闭弹出show()调用的数字。



这可能不是严格正确的,但这是对情节的引用

实例,随后传递给show()。

如果你不想看到它在你的命令末尾加上一个分号

例如。 plot(range(5));


IDLE的问题是由于

python解释器事件循环与事件循环之间缺乏连接而导致的matplotlib(我认为是b $ b)。对我来说,解决方案是安装ipython shell(http://

ipython.scipy.org/moin/)。如果你使用-pylab标志运行ipython然后

你可以交互式matplotlib。例如


plot(range(5),''bo'')

show()

clf()

plot([1,2,3,4,5],range(0,10,2),''r - '')

(不需要另一个show()命令,因为图形显示是已经可见的
...除非当然我在绘图之间删除它

命令)


hth


2007年4月19日16:13:43 -0700, cf ******** @ gmail.com

< cf ******** @ gmail.comwrote:


>


所以,首先,关于[< matplotlib.lines.Line2D实例

在0x017C38C8>]行的内容是什么在我的情节命令后出现?第二,

,当我打电话给show()时,一个新的数字弹出我的罪恶浪潮 - 似乎所有

对,是吗?但是我没有在IDLE中给出另一个>>提示符,直到或者

,除非我关闭弹出show()调用的数字。



这可能不是严格正确的,但这是对情节的引用

实例,随后传递给show()。

如果你不想看到它在你的命令末尾加上一个分号

例如。情节(范围(5));



我的理解是分号技巧特定于IPython,

并且在IDLE中不起作用。我不知道在其他环境中。

您可以将返回的绘图对象列表分配给变量

使命令行不可见但是这些返回值

(与所有返回值一样)不会显示在命令窗口中 (即

传递给stdout)如果从脚本中调用返回它们。


IDLE的问题是由于缺乏

python解释器事件循环与matplotlib的事件循环之间的连接(我想b / b
)。对我来说,解决方案是安装ipython shell(http://

ipython.scipy.org/moin/)。如果你使用-pylab标志运行ipython然后

你可以交互式matplotlib。例如


plot(range(5),''bo'')

show()

clf()

plot([1,2,3,4,5],range(0,10,2),''r - '')

(不需要另一个show()命令,因为图形显示是已经可见的
...除非当然我在绘图之间删除它

命令)



OP似乎正在使用IDLE,其中要尝试的是:


在site-packages / matplotlib / backends / backend_tkagg.py取消注释

line#os.environ [''PYTHONINSPECT''] =''1''


在share / matplotlib / .matplotlibrc中设置interactive = True


使用-n标志启动IDLE


在site-packages / matplotlib / backends / backend_tkagg.py注释掉该行


Tk.mainloop()

函数show中的


-Rob


orangeDinosaur写道:





我正在探索在离开学校时使用python替代

MATLAB的可能性。所以,我最近在我的Windows XP机器上安装了python

2.5.1和matplotlib 0.90之后,我一直在使用matplotlib和

遇到了一些奇怪的行为。这是一个例子
我看到的


>>来自matplotlib。 pylab import *
x = arange(-2 * pi,2 * pi,pi / 24)
y = sin(x)
plot(x,y)



[< matplotlib.lines.Line2D实例位于0x017C38C8>]


>>> show()




所以,首先,关于[< matplotlib]的内容.lines.Line2D实例

在0x017C38C8>]线后出现我的情节命令?第二,

,当我打电话给show()时,一个新的数字弹出我的罪恶浪潮 - 似乎所有

对,是吗?但是我没有在IDLE中给出另一个>>提示符,直到或者

,除非我关闭弹出show()调用的数字。


所以,关闭图后我输入:


>>> show()
情节(x,y)



这次再次出现我的正弦波,我得到

a提示好。但现在,数字窗口完全没有响应 - 我甚至无法关闭它而没有得到你的

程序没有重复。商业。我错过了什么?到目前为止,这个

的行为似乎很不直观。


任何澄清都表示赞赏!


trevis



Trevis,


你可能会看看Numpy,它涉及多维数组。


它有一个小的矩阵组件,并且已经取得了一些进展。

MATLAB可以解决的问题。


Colin W.


Hi,

I am exploring the possibility of using python as a replacement of
MATLAB when I leave school. So, I''ve been playing with matplotlib and
have run into some weird behavior after recently installing python
2.5.1 and matplotlib 0.90 on my Windows XP machine. Here''s an example
of what I see:

>>>from matplotlib.pylab import *
x=arange(-2*pi,2*pi,pi/24)
y=sin(x)
plot(x,y)

[<matplotlib.lines.Line2D instance at 0x017C38C8>]

>>show()


So, first off, what''s up with the [<matplotlib.lines.Line2D instance
at 0x017C38C8>] line that shows up after my plot command? And second,
when I call show(), a new figure pops up with my sin wave -- seems all
right, yes? But I''m not given another >>prompt in IDLE until or
unless I close the figure that popped up with the show() call.

So, after closing the figure I type this:

>>>show()
plot(x,y)

and this time another figure pops up with my sine wave again and I get
a prompt as well. But now, the figure window is completely
unresponsive -- I can''t even close it without getting the "your
program is not repsonding" business. What am I missing? This
behavior so far seems pretty unintuitive.

Any clarification is appreciated!

trevis

解决方案

So, first off, what''s up with the [<matplotlib.lines.Line2D instance
at 0x017C38C8>] line that shows up after my plot command? And second,
when I call show(), a new figure pops up with my sin wave -- seems all
right, yes? But I''m not given another >>prompt in IDLE until or
unless I close the figure that popped up with the show() call.

This may not be strictly correct but thats a reference to the plot
instance which is subsequently passed to show().
If you don''t want to see it put a semicolon at the end of your command
eg. plot(range(5));

The issue with IDLE is to due with lack of connection between the
python interpreter event loop and the event loop of matplotlib (I
think). For me the solution was to install the ipython shell (http://
ipython.scipy.org/moin/). If you run ipython with the -pylab flag then
you can matplotlib interactively. For example

plot(range(5),''bo'')
show()
clf()
plot([1,2,3,4,5],range(0,10,2),''r-'')
(no need for another show() command since the graphics display is
already visible ... unless of course I deleted it in between plot
commands)

hth


On 19 Apr 2007 16:13:43 -0700, cf********@gmail.com
<cf********@gmail.comwrote:

>

So, first off, what''s up with the [<matplotlib.lines.Line2D instance
at 0x017C38C8>] line that shows up after my plot command? And second,
when I call show(), a new figure pops up with my sin wave -- seems all
right, yes? But I''m not given another >>prompt in IDLE until or
unless I close the figure that popped up with the show() call.

This may not be strictly correct but thats a reference to the plot
instance which is subsequently passed to show().
If you don''t want to see it put a semicolon at the end of your command
eg. plot(range(5));

My understanding is that the semicolon trick is specific to IPython,
and does not work in IDLE. I don''t know about in other environments.
You can just assign the list of returned plot objects to a variable to
make it invisible at the command line although these return values
(like all return values) are not "shown in the command window" (i.e.
passed to stdout) if they are returned from calls made in a script.

The issue with IDLE is to due with lack of connection between the
python interpreter event loop and the event loop of matplotlib (I
think). For me the solution was to install the ipython shell (http://
ipython.scipy.org/moin/). If you run ipython with the -pylab flag then
you can matplotlib interactively. For example

plot(range(5),''bo'')
show()
clf()
plot([1,2,3,4,5],range(0,10,2),''r-'')
(no need for another show() command since the graphics display is
already visible ... unless of course I deleted it in between plot
commands)

The OP appears to be using IDLE, for which the things to try are:

In site-packages/matplotlib/backends/backend_tkagg.py uncomment the
line #os.environ[''PYTHONINSPECT''] = ''1''

Set interactive=True in share/matplotlib/.matplotlibrc

Start IDLE with the -n flag

In site-packages/matplotlib/backends/backend_tkagg.py comment out the line

Tk.mainloop()

in the function "show"

-Rob


orangeDinosaur wrote:

Hi,

I am exploring the possibility of using python as a replacement of
MATLAB when I leave school. So, I''ve been playing with matplotlib and
have run into some weird behavior after recently installing python
2.5.1 and matplotlib 0.90 on my Windows XP machine. Here''s an example
of what I see:

>>from matplotlib.pylab import *
x=arange(-2*pi,2*pi,pi/24)
y=sin(x)
plot(x,y)

[<matplotlib.lines.Line2D instance at 0x017C38C8>]

>>>show()



So, first off, what''s up with the [<matplotlib.lines.Line2D instance
at 0x017C38C8>] line that shows up after my plot command? And second,
when I call show(), a new figure pops up with my sin wave -- seems all
right, yes? But I''m not given another >>prompt in IDLE until or
unless I close the figure that popped up with the show() call.

So, after closing the figure I type this:

>>>show()
plot(x,y)


and this time another figure pops up with my sine wave again and I get
a prompt as well. But now, the figure window is completely
unresponsive -- I can''t even close it without getting the "your
program is not repsonding" business. What am I missing? This
behavior so far seems pretty unintuitive.

Any clarification is appreciated!

trevis

Trevis,

You might look at Numpy, which deals with multi-dimensional arrays.

It has a small matrix component and some progress has been made with
MATLAB amenable problems.

Colin W.


这篇关于matplotlib基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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