我正在尝试对齐matplotlib中两个图形的x记号。问题似乎与一个图形是直线图,另一个是条形图有关。我无法通过搜索功能找到解决方案。如果我错过了早些时候发布的解决方案,请告诉我
这是我的代码(sry表示德语变量名^^):
plot_farben = {"cyan": "#55CBCD",
"rot": "#FF968A",
"grün": "#97C1A9",
"orange": "#FFC8A2",
"gelb": "#FFFFB5"}
gridsize = (3, 2)
fig = plt.figure(figsize=(12, 8))
ax1 = plt.subplot2grid(gridsize, (0, 0), colspan=2, rowspan=2)
ax2 = plt.subplot2grid(gridsize, (2, 0), colspan=2)
ax1.fill_between(zeitwerte.index, leistungsband["P1_low"], leistungsband["P1_high"], alpha=0.2, color=plot_farben["cyan"])
ax1.plot(zeitwerte.index, zeitwerte["Solarleistung[kW]"], color=plot_farben["orange"])
ax1.plot(zeitwerte.index, zeitwerte["P1[kW]"], color=plot_farben["cyan"], linestyle='--')
ax1.plot(zeitwerte.index, p1["P1_opt"], color=plot_farben["rot"])
ax1.legend(['Solarleistung', 'P1_Ausgangslastprofil', 'P1_optimiert', 'P1_Flexiband'], loc=0, shadow=True)
ax1.set_title('Laststeuerung mit ToU Tarifen', fontsize=18)
ax1.set_ylabel('Leistung / kW')
ax1.grid(linestyle='--')
ax1.set_xticks(zeitwerte.index)
ax2.bar(zeitwerte.index, zeitwerte["Strompreis[€/kW]"], color=plot_farben["grün"])
ax2.legend(['ToU Strompreis'], loc=0, shadow=True)
ax2.set_xlabel('Zeit / h')
ax2.set_ylabel('Strompreis [€/kWh]')
ax2.grid(linestyle='--')
ax2.set_xticks(zeitwerte.index)
for index, value in enumerate(zeitwerte["Strompreis[€/kW]"]):
plt.text(index + 0.9, value - 0.08, str(value), color="white")
plt.show()
因此,随着约翰的tipp,我将代码更改为followind,现在XTICK已对齐
相关问题 更多 >
编程相关推荐