I'm trying to align my x-ticks from two graphs in matplotlib. The problem seems to be connected to the one graph being a line plot and the other one being a bar chart. I can't find a solution through the search function. Should I have missed a solution posted earlier somewhere, please direct me to it.
This is my code(sry for the German variable names^^):
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()