嗨,我想用小数点删除xtick。我只想离开1992年到1995年。
import pandas as pd
import numpy as np
np.random.seed(12345)
df = pd.DataFrame([np.random.normal(32000,200000,3650),
np.random.normal(43000,100000,3650),
np.random.normal(43500,140000,3650),
np.random.normal(48000,70000,3650)],
index=[1992,1993,1994,1995])
df
#yerr = margin of error or confidence of interval = std/sqrt(pop. size) * z-score, a 95% confidence interval is approximately 1.96
#for under 30, use t-score, otherwise z-score
average = df.mean(axis = 1)
std = df.std(axis = 1)
average, std
#
mgn_error = (std/np.sqrt(df.shape[1])) * 1.96
mgn_error
import matplotlib.pyplot as plt
plt.figure()
xvals = range(df.shape[0])
bars = plt.bar(df.index, average, yerr = mgn_error, color = 'lightslategrey', error_kw=dict(lw=2, capsize=20, capthick=2))
plt.show()
我尝试使用:
plt.xticks(range(df.shape[0]), df.index, alpha = 0.8)
但这是输出: