如何增加 matplotlib 扇形图的大小

问题描述 投票:0回答:1

我有一个角度非常小的极坐标图。但图像的大小就像是 0-pi 的全角度。当我尝试减小无花果高度时,图像宽度也会减小。那么如何增加该图像的尺寸并更有效地将其放置在图形上呢?

我的剧本

def plot_density_rtheta(Rho, xmin, xmax, thetamin, thetamax):
    plt.rcParams.update({'font.size': 15})
    nx = Rho.shape[0]
    ny = Rho.shape[1]
    f1 = plt.figure(figsize=[10,10])
    rad = np.linspace(xmin, xmax, nx)
    azm = np.linspace(thetamin - np.pi/2, thetamax - np.pi/2, ny)
    r, th = np.meshgrid(rad, azm)
            
    ax = plt.subplot(projection="polar")
    ax.axis("off")

    ax.set_thetamin(thetamin*180/np.pi - 90)
    ax.set_thetamax(thetamax*180/np.pi - 90)

    im2 = plt.pcolormesh(th, r, rho, norm = colors.LogNorm(vmin = minRho, vmax = maxRho))
    cax2 = f1.add_axes([0.125,0.92,0.775,0.03])
    plt.colorbar(im2,cax=cax2,orientation='horizontal')
    plt.savefig('density_rtheta.png')
    plt.close()
python matplotlib figsize
1个回答
-1
投票

在 matplotlib 中,当您使用饼图(通常称为扇形图)时,您可能希望增加各个扇形图的大小以获得更好的可视性或强调数据的某些部分。您可以通过调整

wedgeprops
函数中的
pie
参数来实现此目的,特别是控制楔形宽度的
width
参数。

以下是如何创建饼图并增加扇区大小的示例:

import matplotlib.pyplot as plt

# Some example data
sizes = [15, 30, 45, 10]
labels = ['Label 1', 'Label 2', 'Label 3', 'Label 4']

# Create a pie chart
fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, wedgeprops=dict(width=0.3))

# Equal aspect ratio ensures that pie is drawn as a circle
ax.axis('equal')

plt.show()

wedgeprops
字典中,
width
键控制楔形的宽度。较大的值将增加扇区的大小。默认值通常为
0.2
,但您可以根据自己的喜好进行调整。

以下是示例中使用的

pie
函数参数的细分:

  • sizes
    :楔子的比例。
  • labels
    :楔子的标签。
  • autopct
    :显示楔形百分比的字符串格式。
  • startangle
    :第一个楔形的起始角度。
  • wedgeprops
    :楔子的属性字典,其中
    width
    是属性之一。

请记住,使扇区太大可能会导致它们重叠,因此应小心调整此参数。如果您以固定大小的图形显示图表,您可能还需要调整图形大小以适应较大的扇区而不重叠。

© www.soinside.com 2019 - 2024. All rights reserved.