我有這個df:
CODE MONTH PP
24 000136 Enero 57.9
25 000136 Febrero 124.3
26 000136 Marzo 147.7
27 000136 Abril 71.5
28 000136 Mayo 13.2
... ... ...
我正在使用以下代碼繪制圖形:
fig = plt.figure('Graphic', figsize=(30,15), dpi=150)
ax1 = fig.add_axes([0.2, 0.25, 0.60, 0.60])
df.plot(x='MONTH',y='PP',style='--o',color='black',linewidth=8,marker='o',markersize=12, ax=ax1)
ax1.xaxis.set_major_locator(MaxNLocator(min_n_ticks=12))
我想在我的 xaxis 圖中查看月份的所有 12 個值,但我在圖中只得到了 6 個。
我試過了,ax1.xaxis.set_major_locator(MaxNLocator(min_n_ticks=12))但它只繪制刻度,而不是 xaxis 中的值。
你知道我如何繪制所有的 xaxis 值嗎?我只能使用 df.plot
提前致謝。
uj5u.com熱心網友回復:
x 軸刻度會自動顯示,因此請將您希望顯示的件數添加到 x 軸設定中。這將顯示 12 個月。適當添加缺失的資料。
import matplotlib.pyplot as plt
fig = plt.figure('Graphic', figsize=(20,10), dpi=150)
ax1 = fig.add_axes([0.2, 0.25, 0.60, 0.60])
df.plot(x='MONTH',y='PP',style='--o',color='black',linewidth=8,markersize=12, xticks=range(12), ax=ax1)
plt.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457246.html
標籤:Python matplotlib
上一篇:在分類圖中繪制圖例
