【问题标题】:How do I show pie graph in 2 row and 2 column in Python如何在 Python 中以 2 行 2 列显示饼图
【发布时间】:2020-05-30 18:37:14
【问题描述】:

我在显示 2 行 2 列的饼图时遇到了问题。它们在一列中列出。

我该如何解决这个问题?

这是我的代码 sn-ps 如下所示。

plt.figure(figsize = (8,8))
ax1 = plt.subplot(2,2,1)
coursera_df_beginner["course_Certificate_type"].value_counts().plot(kind='pie',shadow=True, explode=(0.1, 0, 0), startangle=90,autopct='%1.1f%%', ax=ax1)
plt.title('Difficulty in Courses')
plt.ylabel("")

plt.figure(figsize = (8,8))
ax2 = plt.subplot(2,2,2)
coursera_df_intermediate["course_Certificate_type"].value_counts().plot(kind='pie',shadow=True, explode=(0.1, 0, 0), startangle=90,autopct='%1.1f%%', ax=ax2)
plt.title('Difficulty in Courses')
plt.ylabel("")

plt.figure(figsize = (8,8))
ax3 = plt.subplot(2,2,3)
coursera_df_mixed["course_Certificate_type"].value_counts().plot(kind='pie',shadow=True, explode=(0.1,), startangle=90,autopct='%1.1f%%', ax=ax3)
plt.title('Difficulty in Courses')
plt.ylabel("")

plt.figure(figsize = (8,8))
ax4 = plt.subplot(2,2,4)
coursera_df_advanced["course_Certificate_type"].value_counts().plot(kind='pie',shadow=True, explode=(0.1, 0), startangle=90,autopct='%1.1f%%', ax=ax4)
plt.title('Difficulty in Courses')
plt.ylabel("")

【问题讨论】:

    标签: python pandas pie-chart


    【解决方案1】:

    这是我的答案

    f,a = plt.subplots(2,2,figsize=(8,8))
    f.subplots_adjust(wspace = .8)
    
    coursera_df_beginner["course_Certificate_type"].value_counts().plot(kind='pie',
                                                                        shadow=True, 
                                                                        explode=(0.1, 0, 0), 
                                                                        startangle=90,
                                                                        autopct='%1.1f%%', ax=a[0,0])
    a[0,0].set_title('Beginner Course')
    a[0,0].set_ylabel('');
    
    
    coursera_df_intermediate["course_Certificate_type"].value_counts().plot(kind='pie',
                                                                            shadow=True, 
                                                                            explode=(0.1, 0, 0), 
                                                                            startangle=90,
                                                                            autopct='%1.1f%%', ax=a[0,1])
    
    a[0,1].set_title('Intermediate Course')
    a[0,1].set_ylabel('');
    
    coursera_df_mixed["course_Certificate_type"].value_counts().plot(kind='pie',
                                                                     shadow=True, 
                                                                     explode=(0.1,), 
                                                                     startangle=90,
                                                                     autopct='%1.1f%%', 
                                                                     ax=a[1,0])
    a[1,0].set_title('Mixed Course')
    a[1,0].set_ylabel('');
    
    coursera_df_advanced["course_Certificate_type"].value_counts().plot(kind='pie',
                                                                        shadow=True,
                                                                        explode=(0.1, 0), 
                                                                        startangle=90,
                                                                        autopct='%1.1f%%', 
                                                                        ax=a[1,1])
    
    a[1,1].set_title('Advanced Course')
    a[1,1].set_ylabel('');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      相关资源
      最近更新 更多