matplotlib示例代码不适用于python虚拟环境 [英] matplotlib example code not working on python virtual environment

查看:174
本文介绍了matplotlib示例代码不适用于python虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在matplotlib中显示图像的x y z坐标. 示例代码在全局python安装中效果很好:当我将光标移动到x,y,z值时即时更新.但是,当我在python虚拟环境上运行示例代码时,我将多次单击图像以使坐标首先显示,然后在不同位置单击时它会进行更新.单击几下后,坐标将不再更新.

I am trying to display the x y z coordinate of an image in matplotlib. the example code work perfectly well on the global python installation: As I move the cursor the x,y,z values get updated instantaneously. However, when I run the example code on a python virtual environment, I would click on the images several times for the coordinate to show in the first place, then when I click on different positions it would update for some. After few clicks, the coordinates will no longer update.

我不知道该如何调试.

I don't know how to debug this.

推荐答案

这可能是matplotlib的macosx后端出现的问题.切换到对matplotlib使用备用后端(例如,使用qt4代替"macosx").有关如何切换后端及其确切含义的详细信息,请参见此处的文档.请注意,您可能必须先安装后端-例如pyqt按照我在这里的建议使用qt4agg后端.

This is likely to be a problem with the macosx backend for matplotlib. Switch to using an alternative backend for matplotlib (e.g. use qt4 instead of 'macosx'). For details of how to switch backend and what exactly that means - see the docs here. Note that you might have to install the backend first - e.g. pyqt to use the qt4agg backend as I'm suggesting here.

总而言之-后端处理matplotlib的输出,并且matplotlib可以针对不同的输出格式.这些可以是gui显示输出格式(例如wxqt4等),也可以是文件输出(例如pdf).这些分别称为交互式后端和非交互式后端.

In summary - the backend deals with the output from matplotlib and matplotlib can target different output formats. These can be gui display output formats (for instance wx, qt4 and so on), or file outputs (for instance pdf). These are known as interactive and non-interactive backends respectively.

要更改后端,请执行

import matplotlib
matplotlib.use('qt4agg')

以代码形式,或者-如果您每次启动matplotlib时都要更改-编辑matplotlibrc文件 a>设置后端属性,例如

in code, or - if you want to change for every time you start matplotlib - edit your matplotlibrc file setting the backend attribute e.g.

backend: Qt4Agg


我收到一条评论提醒,自发布此答案以来,matplotlib文档现在引用了此问题,并且建议一种解决方法,尽管评论者指出,此答案中提供的解决方案(切换到Qt后端)适用于他们无法使用官方文档的解决方法.


N.B. I was alerted by a comment that since posting this answer, matplotlib docs now refer to this issue and suggest a workaround, although the commenter noted that the solution offered in this answer (switch to Qt backend) worked for them where the official docs workaround was not possible for them.

这篇关于matplotlib示例代码不适用于python虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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