scipy-cluster 生成的树状图不显示
我正在使用 scipy-cluster 对某些数据生成层次聚类。作为应用程序的最后一步,我将 dendrogram
函数绘制聚类图。我使用内置的 Python 2.6.1 和 在 Mac OS X Snow Leopard 上运行这个 matplotlib 包。程序运行良好,但最后火箭飞船图标(据我所知,这是 python 中 GUI 应用程序的启动器)出现并立即消失,没有执行任何操作。什么也没显示。如果我在调用后添加“raw_input”,它就会永远在扩展坞中上下弹跳。如果我从终端运行 matplotlib 的简单示例应用程序,它运行良好。有人有这方面的经验吗?
I am using scipy-cluster to generate a hierarchical clustering on some data. As a final step of the application, I call the dendrogram
function to plot the clustering. I am running on Mac OS X Snow Leopard using the built-in Python 2.6.1 and this matplotlib package. The program runs fine, but at the end the Rocket Ship icon (as I understand, this is the launcher for GUI applications in python) shows up and vanishes immediately without doing anything. Nothing is shown. If I add a 'raw_input' after the call, it just bounces up and down in the dock forever. If I run a simple sample application for matplotlib from the terminal it runs fine. Does anyone have any experiences on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 Ubuntu 10.04 上也遇到了同样的问题。
为了从 ipython 交互式控制台显示图形,请使用“-pylab”开关启动它,这可以交互式使用 matplotlib:
要在独立脚本执行期间显示图形,请使用 matplotlib.pyplot.show 调用。这是来自 hcluster 主页的示例,第一行和最后一行是此处的有效位:
I had the same issue on Ubuntu 10.04.
In order to get graphics to display from ipython interactive console, start it with "-pylab" switch, which enables the interactive use of matplotlib:
To get your graphics to display during the execution of a standalone script, use matplotlib.pyplot.show call. Here's an example from hcluster homepage, the first and last line are the significant bits here:
使用“-pylab”开关调用 ipython 对我来说没有什么区别。
(系统:Fedora 13)
虽然并不理想,但我的解决方案是将结果图显式写入文件。
例如:
希望这对遇到同样问题的人有所帮助。
修正:在 hcluster 包的简短教程中简单使用复制粘贴时要小心,特别是如果您在教程中显示的几种类型的树状图绘制之后调用 pylab.savefig() ,即,则
exampleDendrogram.png 将包含同一张图中的单连锁树状图和全连锁树状图,它们很可能会交叉,看起来很乱。
如果你像我一样愚蠢,你会花 30-180 分钟对如何正确使用 hcluster 感到困惑,而实际上这只是在树状图调用之间重置 matplotlib 的问题:
现在,生成的树状图图像文件将如下所示你期望它们看起来像。
Invoking ipython with "-pylab" switch didn't make a difference for me.
(System: Fedora 13)
Though not ideal, my solution was to explicitly write the resulting figure as a file.
For example:
Hope this helps anyone who is running into the same issue.
Amendment: Be careful about simply using copy-and-paste with the hcluster package's brief tutorial, notably in that if you call pylab.savefig() after several types of dendrogram drawing shown in the tutorial, i.e.
Then exampleDendrogram.png will contain both the single-linkage dendrogram and the complete-linkage dendrogram in the same figure, and they will likely cross-cross and look like a mess.
If you're as stupid as me, you'll spend 30-180 minutes in confusion about how to properly use hcluster, when it's actually just a matter of resetting matplotlib between dendrogram calls:
Now, the resulting dendrogram image files will look like what you expected them to look like.
我也遇到过同样的问题。您可以使用以下方法之一
使用 plt.show() :
在 dedogram 之后使用 plt.show() ,这将显示绘图
使用 plt.show
在 jupyter 笔记本中首先使用 %matplotlib 内联。这将显示执行后的情节。
使用 matplotlib 内联
I have been facing the same problem. You can use one of the below methods
Use plt.show() :
use plt.show() after dedogram, this will show the plot
using plt.show
Use %matplotlib inline intially in jupyter notebook. this will show the plot after execution.
Using matplotlib inline