擅长:python、mysql、java
<p>以前的答复有一些线索,但没有显示详尽的答案。
您必须设置自定义的xtick标签并按如下方式旋转:</p>
<pre><code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame(
{'month': ['201501', '201502', '201503', '201504', '201505'],
'total_gmv': [np.nan, 2.824294e+09, 7.742665e+09, 2.024132e+10, 6.705012e+10]})
df['month'] = pd.to_datetime(df['month'], format='%Y%m', errors='ignore')
ax = df.plot(kind='bar')
ax.set_xticklabels(df['month'].dt.strftime('%b, %Y'))
plt.xticks(rotation=0)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/aPhQw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aPhQw.png" alt="enter image description here"/></a></p>