Page 1 of 1

XTICK Beschriftungen, die nicht auf der Python -Linie -Diagramm angezeigt werden

Posted: 05 Apr 2025, 22:21
by Anonymous
Mein Python -Abgangskodex gegenüber Jahren, unten funktioniert einwandfrei für eine Bar -Handlung. Ich hätte gerne JAHRE-Zeckensmarke auf der X-Achse. Derzeit bekomme ich die Linienhandlung, aber keine Jahre, die auf der X-Achse gekennzeichnet sind. Für die Barhandlung sind die Jahre in Ordnung. Dies ist kein Mehrfachplot (oder Nebenhandlungen), sondern das Zeilendiagramm, während die Stabplotting kommentiert wird, und umgekehrt. Ich bin nur neugierig, warum einer funktioniert und der andere nicht.

Code: Select all

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_csv('../RnOut/RAINFALL/Deps/CHIPAT.txt', sep=' ', skipinitialspace=True )

fig, ax = plt.subplots(figsize=(10, 10))

#Drop rows with missing values
#*****************************
df_new = df.drop(df[df['Dep'] = 0 else 'r' for e in df_new['Dep']]
plt.bar(df_new['Year'],df_new['Dep'], color=colors,edgecolor='black')

#Set titles
#**********
ax.set_title('Rainfall Departures: Oct-Mar\n ---------------------------------------')
plt.xlabel("Years")
plt.ylabel("Rainfall Departure (Std Dev)")

ax.grid()
plt.savefig('ChipatDep.png')
plt.show()
< /code>
Meine Beispieldaten < /p>
Year  Dep
1945  -0.9
1946   0.9
1947   0.6
1948  -0.7
1949   1.2
1950  -0.9
1951   0.9
1952   0.1
1953  -1.0
1954   1.3
1955  -0.3