首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matplotlib subplot -图表被覆盖

Matplotlib subplot -图表被覆盖
EN

Stack Overflow用户
提问于 2020-10-04 21:39:13
回答 1查看 21关注 0票数 0

我想根据以下数据创建两个饼图:

代码语言:javascript
复制
post_type   owner_user_id   year_posted score   count
A           150165022       332372      2567380 35846
Q           112349610       283997       180680 2111

一个由score创建,另一个由count创建,并按post_type分组。因此,我使用以下代码:

代码语言:javascript
复制
axes[0].labels = ['answers', 'questions']
axes[0].sizes = buffer_df['score']
axes[0].explode = (0, 0.3)
axes[0].pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',shadow=True, startangle=90)
axes[0].axis('equal')

axes[1].labels = ['answers a', 'questions a']
axes[1].sizes = buffer_df['count']
axes[1].explode = (0, 0.3)
axes[1].pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',shadow=True, startangle=90)
axes[1].axis('equal')

plt.show()

但我只画了两次第一张图:

我知道这是第一个图表,因为我更改了第二个图表的标签。

谁能告诉我,我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-04 22:01:26

我不知道为什么会这样,但如果你直接描述它,你就可以画出你想要的东西。

代码语言:javascript
复制
import matplotlib.pyplot as plt

fig, axes= plt.subplots(1,2, figsize=(12,9))

axes[0].pie(buffer_df['score'], explode=(0, 0.3), labels=['answers', 'questions'], autopct='%1.1f%%',shadow=True, startangle=90)
axes[0].axis('equal')
axes[1].pie(buffer_df['count'], explode=(0, 0.3), labels=['answers a', 'questions a'], autopct='%1.1f%%',shadow=True, startangle=90)
axes[1].axis('equal')

plt.show()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64195337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档