Matplotlib:同一图中的两个树图

pkwftd7m  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(128)

我是matplotlib et squarify的新手,我想在同一个图中显示两个不同的树图。
我使用下面的代码显示两个树图在相同的轴,我不明白为什么。

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

字符串

y53ybaqx

y53ybaqx1#

您可以将要打印的轴指定为kwarg 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()

字符串
输出量:


的数据

相关问题