Параметры Matplotlib на графике ap ie, размер процентов, цвета - PullRequest
0 голосов
/ 23 апреля 2020

Я работаю над проектом глобального потепления, и мне нужно показать влияние промышленности (человечество) на окружающую среду. Я решил сделать ап ie гистограмму, чтобы объяснить это с помощью DataViz. На самом деле, моя визуализация довольно хорошая, p ie показывает выброс CO2 в различных секторах (энергетика, сельское хозяйство ...) и гистограмму, связывающую энергетический сектор, которая показывает детали энергетического сектора (транспорт, промышленность). ...). Я хотел хорошо рассмотреть это, но есть некоторая ошибка: - не метки на графике p ie (в легенде я могу сделать это, но я хочу их на p ie) - размер процента на р ie слишком мало ... - размер процента на гистограмме тоже маловат и меняем цвет - ставим заголовок для фигуры

Код довольно сложный, и я не найти галочки, чтобы изменить эти мелочи, я пытался в течение 2 дней ... Пожалуйста, помогите .. Я новичок, я изучаю это в течение одного месяца, это мой первый «сложный график», и мне нужна помощь ^^ Я хотел бы, чтобы моя презентация была идеальной .............................! введите описание изображения здесь

import numpy as np
from matplotlib.patches import ConnectionPatch

#creation database and percent
dfEmissionsbyindusv2
df_pie = dfEmissionsbyindusv2.sum()
df_pie2 = df_pie.drop(['Year', 'Total emissions excluding LULUCF', 'Energy Industries', 'Manufacturing industries and construction', 'Transport', 'Residential and other sectors', 'Energy - Other', 'Fugitive Emissions from Fuels', 'CO2 from Transport and Storage'])


#creation figure
fig = plt.figure(figsize=(30, 15))
ax1 = fig.add_subplot(122)
ax2 = fig.add_subplot(121)
fig.subplots_adjust(wspace=-0.25)

# graphe 1 : pie chart percent by sector
#labels = ('Energy', 'Agriculture', 'Waste', 'Other', 'Industrial processes and product use')
#angle = -180 * ratios[0]
ax1.pie(df_pie2, autopct='%1.1f%%', startangle=45, explode = (0.1,0,0, 0, 0), textprops=dict(color = "w"))
ax1.legend(('Energy', 'Agriculture', 'Waste', 'Other', 'Industrial processes and product use'))


# graphe 2 : bar chart zoom industry sector
xpos = 0
bottom = 0
ratios = [ratio1,ratio2,ratio3,ratio4,ratio5,ratio6,ratio7]
width = 1

colors = [[.1, .3, .9], [.1, .3, .7], [.1, .3, .5], [.1, .3, .3], [.1, .3, .2], [.1, .3, .2], [.1, .1, .1]]

for j in range(len(ratios)):
    height = ratios[j]
    ax2.bar(xpos, height, width, bottom=bottom, color=colors[j])
    ypos = bottom + ax2.patches[j].get_height() / 2
    bottom += height
    ax2.text(xpos, ypos, "%d%%" % (ax2.patches[j].get_height() * 100),
             ha='center')

ax2.legend(('Energy Industries', 'Manufacturing industries and construction', 'Transport', 'Residential and other sectors', 'Energy - Other', 'Fugitive Emissions from Fuels', 'CO2 from Transport and Storage'))
ax2.axis('off')
ax2.set_xlim( - 2.5 * width,  2.5 * width)

# 
theta1, theta2 = ax1.patches[1].theta1, ax1.patches[-1].theta2
center, r = ax1.patches[0].center, ax1.patches[-1].r
bar_height = sum([item.get_height() for item in ax2.patches])


# 
x = r * np.cos(np.pi / 180 * theta2) + center[0]
y = np.sin(np.pi / 180 * theta2) + center[-1]
con = ConnectionPatch(xyA=(width / 2, bar_height), xyB=(x, y),
                      coordsA="data", coordsB="data", axesA=ax2, axesB=ax1)
con.set_color([0, 0, 0])
con.set_linewidth(2)
ax2.add_artist(con)

# 
x = r * np.cos(np.pi / 180 * theta1) + center[0]
y = np.sin(np.pi / 180 * theta1) + center[-1]
con = ConnectionPatch(xyA=(width / 2, 0), xyB=(x, y), coordsA="data",
                      coordsB="data", axesA=ax2, axesB=ax1)
con.set_color(c ='black')
ax2.add_artist(con)
con.set_linewidth(2)


plt.show()
...