在Python中创建圆形类型的饼图子块

在Python中创建圆形类型的饼图子块,python,matplotlib,Python,Matplotlib,我正在尝试使用DF在绘图中创建饼图子图。但我所有的饼图都不是实际的圆形,但前两个是椭圆。请指导我如何制作所有大小和圆形相同的子图。 下面给出了我正在使用的代码 fig = plt.figure() ax1 = plt.subplot(131) ax2 = plt.subplot(132) ax3 = plt.subplot(133) ax1 = test1_pie.plot(kind='pie',y=test1,ax =ax1) plt.axis('equal') ax2 = test2_p

我正在尝试使用DF在绘图中创建饼图子图。但我所有的饼图都不是实际的圆形,但前两个是椭圆。请指导我如何制作所有大小和圆形相同的子图。 下面给出了我正在使用的代码

fig = plt.figure()
ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)

ax1 = test1_pie.plot(kind='pie',y=test1,ax =ax1)
plt.axis('equal')

ax2 = test2_pie.plot(kind='pie',y=test2,ax=ax2)
plt.axis('equal')

ax3 = test3_pie.plot(kind='pie',y=test3,ax=ax3)
plt.axis('equal')

混合使用状态机
pyplot
调用和普通方法调用是个坏主意。这是一个典型的例子

plt.
将引用在这种情况下创建的最后一个轴。您只对最后一个axis对象调用了
axis('equal')

最好还是坚持使用法线轴方法api

例如:

fig = plt.figure()
ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)

ax1 = test1_pie.plot(kind='pie', y=test1, ax=ax1)
ax1.axis('equal')

ax2 = test2_pie.plot(kind='pie', y=test2, ax=ax2)
ax2.axis('equal')

ax3 = test3_pie.plot(kind='pie', y=test3, ax=ax3)
ax3.axis('equal')
作为一个独立的例子:

import numpy as np
import matplotlib.pyplot as plt

fig, axes = plt.subplots(ncols=3)

for ax in axes:
    x = np.random.random(np.random.randint(3, 6))
    ax.pie(x)
    ax.axis('equal')

plt.show()

也可以尝试使用
饼图
功能。还要发布一个完整的代码来重现这个问题。@Azad,使用特定的绘图类型进行标记可能会产生比实际帮助更多的噪音。根据经验,我只会添加一些标签,你可以想象人们会选择这些标签。@cel好的,你可以right@MoChen,你可能想给我们一个机会。