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

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

Matplotlib : Two treemaps in the same figure

问题

  1. 我是新手matplotlibsquarify不太熟悉我想在同一张图中显示两个不同的矩形树图
  2. 我使用下面的代码在同一坐标轴上显示了两个矩形树图但我不明白为什么
  3. http_return_status_label_1 = ['200', '300', '500']
  4. http_return_status_count_1 = [4, 8, 12]
  5. http_return_status_label_2 = ['2000', '3000', '5000']
  6. http_return_status_count_2 = [40, 88, 102]
  7. fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
  8. ax1.subplot = squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8)
  9. ax2.subplot = squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8)
  10. plt.axis('off')
  11. 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.

  1. http_return_status_label_1 = ['200','300','500']
  2. http_return_status_count_1 =[4,8,12]
  3. http_return_status_label_1 = ['2000','3000','5000']
  4. http_return_status_count_1 =[40,88,102]
  5. fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
  6. ax1.subplot = squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8)
  7. ax2.subplot = squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8)
  8. plt.axis('off')
  9. plt.show()

答案1

得分: 1

您可以使用关键字参数 ax= 来指定要绘制的轴(参见文档)。此外,您可以禁用每个轴的坐标轴:

  1. import matplotlib.pyplot as plt
  2. import squarify
  3. http_return_status_label_1 = ['200', '300', '500']
  4. http_return_status_count_1 = [4, 8, 12]
  5. http_return_status_label_2 = ['2000', '3000', '5000']
  6. http_return_status_count_2 = [40, 88, 102]
  7. fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
  8. squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8, ax=ax1)
  9. squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8, ax=ax2)
  10. ax1.axis('off')
  11. ax2.axis('off')
  12. 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:

  1. import matplotlib.pyplot as plt
  2. import squarify
  3. http_return_status_label_1 = ['200','300','500']
  4. http_return_status_count_1 =[4,8,12]
  5. http_return_status_label_2 = ['2000','3000','5000']
  6. http_return_status_count_2 =[40,88,102]
  7. fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'aspect': 'equal'})
  8. squarify.plot(sizes=http_return_status_count_1, label=http_return_status_label_1, alpha=.8, ax=ax1)
  9. squarify.plot(sizes=http_return_status_count_2, label=http_return_status_label_2, alpha=.8, ax=ax2)
  10. ax1.axis('off')
  11. ax2.axis('off')
  12. 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:

确定