问题描述
我正在尝试绘制以下内容的 season clustermap (它也不适用于 heatmap ),没有以下内容承认:
I'm trying to plot a seaborn clustermap (it doesn't work with the heatmap too) with the following, no NaNs admitted:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
def plotClusterMap():
a = pd.DataFrame(np.matrix('1 2; 3 4'))
print a
fig = plt.figure()
sns.clustermap(a)
plt.show()
a
格式正确:
0 1
0 1 2
1 3 4
控制台输出:
Traceback (most recent call last):
File "main.py", line 78, in <module>
main()
File "main.py", line 72, in main
heatmapPlotter.plotClusterMap()
File "/Users/username/code.py", line 12, in plotClusterMap
sns.clustermap(a)
File "/Library/Python/2.7/site-packages/seaborn/matrix.py", line 895, in clustermap
**kwargs)
File "/Library/Python/2.7/site-packages/seaborn/matrix.py", line 813, in plot
self.plot_matrix(colorbar_kws, mask, **kws)
File "/Library/Python/2.7/site-packages/seaborn/matrix.py", line 803, in plot_matrix
cbar_kws=colorbar_kws, mask=mask, **kws)
File "/Library/Python/2.7/site-packages/seaborn/matrix.py", line 292, in heatmap
plotter.plot(ax, cbar_ax, kwargs)
File "/Library/Python/2.7/site-packages/seaborn/matrix.py", line 177, in plot
if axis_ticklabels_overlap(xtl):
File "/Library/Python/2.7/site-packages/seaborn/utils.py", line 374, in axis_ticklabels_overlap
bboxes = [l.get_window_extent() for l in labels]
File "/usr/local/lib/python2.7/site-packages/matplotlib/text.py", line 796, in get_window_extent
raise RuntimeError('Cannot get window extent w/o renderer')
RuntimeError: Cannot get window extent w/o renderer
- Mac OSX: 10.10.3( edit )
- Seaborn:0.5.1
- Matplotlib:1.3.1(从1.4降级)
- 脾气暴躁:1.8.0
- Python:2.7.9
- Mac OSX: 10.10.3 (edit)
- Seaborn: 0.5.1
- Matplotlib: 1.3.1 (just downgraded from 1.4)
- Numpy: 1.8.0
- Python: 2.7.9
推荐答案
我正在使用Mac OS X 10.9.5,python 2.7.9,matplotlib 1.4.3和seaborn 0.5.1.我能够重现该错误.
I'm using Mac OS X 10.9.5, python 2.7.9, matplotlib 1.4.3, and seaborn 0.5.1. I was able to reproduce the error.
默认情况下,我将macosx
后端用于matplotlib.如果我将后端更改为qt4agg
(需要PyQt4),tkagg
或webagg
,则您的代码有效.这是对我有用的脚本:
By default I am using the macosx
backend for matplotlib. Your code works if I change the backend to qt4agg
(requires PyQt4), tkagg
or webagg
. Here's the script that worked for me:
import numpy as np
import pandas as pd
import matplotlib
matplotlib.use('qt4agg') # Can also use 'tkagg' or 'webagg'
import matplotlib.pyplot as plt
import seaborn as sns
def plotClusterMap():
a = pd.DataFrame(np.matrix('1 2; 3 4'))
print a
# fig = plt.figure()
sns.clustermap(a)
plt.show()
if __name__ == "__main__":
plotClusterMap()
请注意,我已注释掉fig = plt.figure()
. clustermap
似乎是在创建自己的人物.
Note that I commented out fig = plt.figure()
. clustermap
appears to create its own figure.
这篇关于Seaborn matplotlib:无法获取不带渲染器的窗口范围(RuntimeError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!