Python 使用matplotlib优化图表的显示

Python 使用matplotlib优化图表的显示,python,python-3.x,matplotlib,legend,Python,Python 3.x,Matplotlib,Legend,我使用Python 3.43和Matplotlib 1.5.0。 我创建了一个小示例: # -*- coding: utf-8 -*- import matplotlib matplotlib.use("Qt5Agg") matplotlib.use("Svg") import matplotlib.pyplot as plt txts = ['Bau', 'Landwirtschaft', 'Handel', 'Logistik', 'Handwerk', 'Gaststätten', 'F

我使用Python 3.43和Matplotlib 1.5.0。 我创建了一个小示例:

# -*- coding: utf-8 -*-
import matplotlib
matplotlib.use("Qt5Agg")
matplotlib.use("Svg")
import matplotlib.pyplot as plt

txts = ['Bau', 'Landwirtschaft', 'Handel', 'Logistik', 'Handwerk', 'Gaststätten', 'Freiberufler', 'Dienstleistungen', 'Finanzanbieter', 'Handel', 'Einzelhandel', 'Vertrieb', 'Touristik', 'sonstige']
sizes = [104, 351, 1339, 456, 831, 661, 465, 323, 304, 294, 152, 133, 1006, 631]
ch_farben = ['#FF0000', '#0064EB', '#FFD700', '#00FF00', '#00CED1', '#006400', '#556B2F', '#87CEEB', '#DC143C', '#FFFACD', '#99FFCC', '#CD853F', '#20B2AA', '#C71585']

#Größe Picture in Inch
width_inch = 10.0
height_inch = 10.0
# Aulösung in dpi
dpis = 100
# Rand um Diagramm in Pixel
rand = 50
#Breite des Balkens >0 und <= 1
bar_width = 0.8
xpos = ()
lg_beschr = []
cnt_bars = len(sizes)
ymax =max(sizes)
smm = sum(sizes)
ymax = ymax
nc = cnt_bars // 10 + 1
for j in range(cnt_bars):
    if smm != 0:
        sprz = "%2.1f%%" % (100 * sizes[j]/smm)
    if len(sprz) > 0:
        lg_beschr.append(txts[j] + "  (" + sprz + ")")
    else:
        lg_beschr.append(txts[j])
    xpos = xpos + (j + (1 - bar_width)/2,)
br =cnt_bars
d = dict(left=xpos, width=bar_width, height= sizes, bottom=0, color=ch_farben)
sp111 =plt.subplot(111)
bars = sp111.bar(**d )
fig = plt.gcf()
fig.dpi = dpis
fig.set_figwidth(width_inch)
fig.set_figheight(height_inch)
rdx = rand / (width_inch * dpis)
rdy = rand / (height_inch * dpis)
fig.subplots_adjust(bottom=rdy, top=1.0-rdy, left=rdx, right=1.0-rdx)
sp111.set_position([0.05, 0.05, 0.72, 0.72])
ax = plt.gca()
chart_leg = ax.legend(bars, lg_beschr, loc='lower left', bbox_to_anchor=(0.0, 1.0), frameon= True, fontsize =14, ncol=nc, borderaxespad=0.1)
plt.draw()
#Speichern in svg-Dateien
plt.savefig("D:/TMP/test_diag.svg", format="svg", transparent=True, dpi=dpis)
plt.savefig("D:/TMP/test_diag.png", format="png", transparent=True, dpi=dpis)
plt.show()
plt.close()
手动设置较小的值以获取所有图例。有可能吗 自动化这个?
是否有计算图例大小和位置的选项(以像素、英寸或轴坐标为单位)?

是否有帮助?谢谢您的回答,但我认为自动图例在matplotlib 1.5中不起作用?它应该仍然起作用,但文档似乎已移动。有帮助吗?谢谢您的回答,但是我认为auto legend在matplotlib 1.5中不起作用?它应该仍然起作用,但文档似乎被移动了。
sp111.set_position([0.05, 0.05, 0.72, 0.72])