【发布时间】:2022-01-07 20:43:52
【问题描述】:
我无法在不同大小的饼图之间设置相等的间距。 5 个正确排列成一排,但相邻馅饼的轮廓之间的距离不相等。我尝试了以下代码的许多缩写,它们都没有对输出产生很大影响(见图):
#代码:
import matplotlib.pyplot as plt
import pandas as pd
labels = 'Verkehr', 'Maschinen und Motoren', 'Feuerungen', 'Industrie / Gewerbe', 'Land- und Forstwirtschaft'
sizesax1 = [108295, 10107, 7220, 11551, 7220]
sizesax2 = [77882, 6676, 6676, 13351, 6676]
sizesax3 = [55652, 4417, 6184, 15900, 6184]
sizesax4 = [36327, 2642, 4632, 16512, 5944]
sizesax5 = [18781, 1409, 3287, 1878, 4695]
fig, (ax1, ax2, ax3, ax4, ax5) = plt.subplots(1, 5, figsize =(20,4))
ax1.pie(sizesax1, startangle=0, colors = ('red', 'darkblue', 'orange', 'yellow', 'green'), radius=1*4)
ax2.pie(sizesax2, startangle=0, colors = ('red', 'darkblue', 'orange', 'yellow', 'green'), radius=.77*4)
ax3.pie(sizesax3, startangle=0, colors = ('red', 'darkblue', 'orange', 'yellow', 'green'), radius=.61*4)
ax4.pie(sizesax4, startangle=0, colors = ('red', 'darkblue', 'orange', 'yellow', 'green'), radius=.46*4)
ax5.pie(sizesax5, startangle=0, colors = ('red', 'darkblue', 'orange', 'yellow', 'green'), radius=.33*4)
我尝试了一些补充:
fig.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=1, hspace=None)
或
fig.tight_layout()
#giving me this error message:
/srv/conda/envs/notebook/lib/python3.7/site-packages/ipykernel_launcher.py:17: UserWarning:
Tight layout not applied. The bottom and top margins cannot be made large enough to
accommodate all axes decorations.
还有一些其他的。
非常感谢您阅读本文!我是 python 的一个完整的初学者,只是设法达到你在这张图片中看到的:
【问题讨论】:
-
这个定义有点不明确。您是否希望馅饼之间的空白相同,或者您是否希望中心之间的距离相同?还有半径需要有多精确?
标签: python-3.x pandas matplotlib jupyter-notebook pie-chart