【问题标题】:better piechart color scheme更好的饼图配色方案
【发布时间】:2017-11-14 16:00:59
【问题描述】:

我正在尝试创建一个饼图,如下:

import matplotlib.pyplot as plt
import pandas as pd

# make a square figure and axes
plt.figure(1, figsize=(10,10))
plt.axes([0.01, 0.1, 0.6, 0.6])
# plt.style.use('fivethirtyeight')

# The slices will be ordered and plotted counter-clockwise.
labels = 'foo1', 'foo2', 'foo3', 'foo4'
fracs = pd.Series([10,30, 50,10],index=labels) 
fracs.plot(kind='pie', labels=None, autopct='%1.0f%%')
plt.legend(bbox_to_anchor=(0.95, .9), loc=2, borderaxespad=0.,labels=labels)
plt.title('pie chart demo which should be center aligned not left', bbox={'facecolor':'0.8', 'pad':5})

plt.show()

这是一个饼图: 但是,我面临两个问题: 1)我不喜欢配色方案。我想要一个更符合 的配色方案(我需要 12 种颜色) 2) 标题仅以饼图为中心。传说不知何故出来了。我正在尝试将标题置于图表和图例的中心。

有人可以帮忙吗?

【问题讨论】:

    标签: python-3.x pandas matplotlib pie-chart


    【解决方案1】:

    我认为这是您试图模仿的 ggplot 颜色方案。

    而您的 plt.axes 命令就是将您的图表向左移动的原因。

    试试这个:

    import matplotlib.pyplot as plt
    
    plt.style.use('ggplot')
    plt.figure(1, figsize=(10,10))
    
    labels = 'foo1', 'foo2', 'foo3', 'foo4'
    sizes = [10,30, 50,10]
    plt.pie(sizes, labels=labels)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多