Matplotlib:同一图中的两个树状图

huangapple go评论80阅读模式
英文:

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()

输出:

Matplotlib:同一图中的两个树状图

英文:

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:

Matplotlib:同一图中的两个树状图

huangapple
  • 本文由 发表于 2023年7月10日 17:33:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652463.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定