2017-07-06 68 views
1

我使用plotnine生成散點圖,其中x軸是pandas.Timestamp對象。使用plotnine更改刻度標籤

當前,x刻度標籤(例如「2017-07-01」)正在彼此碰撞。我希望能夠對刻度標籤進行任意轉換。如何更改圖上的x刻度標籤?

它看起來像我可以做一些像+ scale_x_continuous(labels=???)但我不知道什麼參數傳遞給標籤。

回答

2

我問這個問題上的plotnine項目的issue,並得到了本作的解決方案:

from mizani.breaks import date_breaks 
from mizani.formatters import date_format 

... 
+ scale_x_datetime(breaks=date_breaks('1 year'), labels=date_format('%Y')) 

這也將做到這一點:

+ scale_x_datetime(labels=lambda lst: [x.year if x.month==1 and x.day==1 else "" for x in lst])