【问题标题】:Increase Pie Chart Dimensions with matplotlib [duplicate]使用 matplotlib 增加饼图尺寸 [重复]
【发布时间】:2021-12-02 18:11:23
【问题描述】:
import matplotlib.pyplot as plt

months = ['January', 'February', 'March']
months_sizes = [16.13, 26.64, 57.23]
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weekdays_sizes = [1.79, 2.23, 2.67, 3.26, 2.78, 1.50, 1.91, 2.21, 1.94, 1.98, 1.37, 2.58, 6.72, 9.83, 5.95, 6.69, 7.52, 5.42, 5.27, 7.28, 19.11]
months_colors = ['#081a28', '#2e1d0b', '#15210f']
weekdays_colors = ['#2986cc', '#2478b7', '#206ba3', '#1c5d8e', '#18507a', '#144366', '#103551',
                   '#e69138', '#cf8232', '#b8742c', '#a16527', '#8a5721', '#73481c', '#5c3a16',
                   '#6aa84f', '#5f9747', '#54863f', '#4a7537', '#3f642f', '#355427', '#2a431f']
outer_circle = plt.pie(months_sizes, labels=months, colors=months_colors, startangle=90, frame=True)
inner_circle = plt.pie(weekdays_sizes, labels=weekdays, colors=weekdays_colors, radius=0.7, startangle=90, labeldistance=0.7)
centre_circle = plt.Circle((0, 0), 0.35, color='white', linewidth=0)

fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.plot(figsize=(19,8))
plt.show()

到目前为止,这是我的代码。它做我想要的,但我需要它更大。但是我无法做到这一点,figsizeradius= 都没有。 如何使用已有的代码实现我想要的?

[我得到的饼图]

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:
    plt.figure(figsize = (24, 24))
    outer_circle = plt.pie(months_sizes, labels=months, colors=months_colors, startangle=90, frame=True)
    # ... the rest of the code ...
    

    figsize 适合我

    【讨论】:

      【解决方案2】:

      在绘制之前创建一个更大尺寸的图形:

      # your plot setup
      import matplotlib.pyplot as plt
      
      months = ['January', 'February', 'March']
      months_sizes = [16.13, 26.64, 57.23]
      weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun','Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      weekdays_sizes = [1.79, 2.23, 2.67, 3.26, 2.78, 1.50, 1.91, 2.21, 1.94, 1.98, 1.37, 2.58, 6.72, 9.83, 5.95, 6.69, 7.52, 5.42, 5.27, 7.28, 19.11]
      months_colors = ['#081a28', '#2e1d0b', '#15210f']
      weekdays_colors = ['#2986cc', '#2478b7', '#206ba3', '#1c5d8e', '#18507a', '#144366', '#103551',
                         '#e69138', '#cf8232', '#b8742c', '#a16527', '#8a5721', '#73481c', '#5c3a16',
                         '#6aa84f', '#5f9747', '#54863f', '#4a7537', '#3f642f', '#355427', '#2a431f']
      
      # create figure
      fig, ax = plt.subplots(figsize=(19, 8))
      
      # plot using ax
      outer_circle = ax.pie(months_sizes, labels=months, colors=months_colors, startangle=90, frame=True)
      inner_circle = ax.pie(weekdays_sizes, labels=weekdays, colors=weekdays_colors, radius=0.7, startangle=90, labeldistance=0.7)
      centre_circle = plt.Circle((0, 0), 0.35, color='white', linewidth=0)
      ax.add_artist(centre_circle)
      
      plt.show()
      

      【讨论】:

      • 谢谢,成功了!
      猜你喜欢
      • 2021-02-07
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 2019-08-05
      • 2015-01-27
      • 2017-02-10
      • 1970-01-01
      • 2018-05-21
      相关资源
      最近更新 更多