英文:
Matplotlib : Two treemaps in the same figure
问题
我是新手,对matplotlib和squarify不太熟悉,我想在同一张图中显示两个不同的矩形树图。
我使用下面的代码,在同一坐标轴上显示了两个矩形树图,但我不明白为什么。
http_return_status_label_1 = ['200', '300', '500']
http_return_status_count_1 = [4, 8, 12]
http_return_status_label_2 = ['2000', '3000', '5000']
http_return_status_count_2 = [40, 88, 102]
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
ax1.subplot = squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8)
ax2.subplot = squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8)
plt.axis('off')
plt.show()
英文:
I'm new to matplotlib et squarify and I want to display two distinct treemaps in the same figure.
I use the code below which display the two treemaps in the same axes and i don't get why.
http_return_status_label_1 = ['200','300','500']
http_return_status_count_1 =[4,8,12]
http_return_status_label_1 = ['2000','3000','5000']
http_return_status_count_1 =[40,88,102]
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
ax1.subplot = squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8)
ax2.subplot = squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8)
plt.axis('off')
plt.show()
答案1
得分: 1
您可以使用关键字参数 ax=
来指定要绘制的轴(参见文档)。此外,您可以禁用每个轴的坐标轴:
import matplotlib.pyplot as plt
import squarify
http_return_status_label_1 = ['200', '300', '500']
http_return_status_count_1 = [4, 8, 12]
http_return_status_label_2 = ['2000', '3000', '5000']
http_return_status_count_2 = [40, 88, 102]
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8, ax=ax1)
squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8, ax=ax2)
ax1.axis('off')
ax2.axis('off')
plt.show()
输出:
英文:
You can specify the ax you want to plot to as a kwarg ax=
(see the doc). Also, you can disable the axis for each ax:
import matplotlib.pyplot as plt
import squarify
http_return_status_label_1 = ['200','300','500']
http_return_status_count_1 =[4,8,12]
http_return_status_label_2 = ['2000','3000','5000']
http_return_status_count_2 =[40,88,102]
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8, ax=ax1)
squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8, ax=ax2)
ax1.axis('off')
ax2.axis('off')
plt.show()
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论