【发布时间】:2022-09-27 11:16:35
【问题描述】:
我有一个数据框region_cumulative_df_sel,如下所示:
Month-Day regions RAIN_PERCENTILE_25 RAIN_PERCENTILE_50 RAIN_PERCENTILE_75 RAIN_MEAN RAIN_MEDIAN
07-01 1 0.0611691028 0.2811064720 1.9487996101 1.4330813885 0.2873695195
07-02 1 0.0945720226 0.8130480051 4.5959815979 2.9420840740 1.0614821911
07-03 1 0.2845511734 1.1912839413 5.5803232193 3.7756001949 1.1988518238
07-04 1 0.3402922750 3.2274529934 7.4262523651 5.2195668221 3.2781836987
07-05 1 0.4680584669 5.2418060303 8.6639881134 6.9092760086 5.3968687057
07-06 1 2.4329853058 7.3453550339 10.8091869354 8.7898645401 7.5020875931
... ...
... ...
... ...
06-27 1 382.7809448242 440.1162109375 512.6233520508 466.4956665039 445.0971069336
06-28 1 383.8329162598 446.2222900391 513.2116699219 467.9851379395 451.1973266602
06-29 1 385.7786254883 449.5384826660 513.4027099609 469.5671691895 451.2281188965
06-30 1 386.7952270508 450.6524658203 514.0201416016 471.2863159180 451.2484741211
索引\"Month-Day\" 是String 类型,表示日历年的第一天和最后一天,而不是日期时间类型。
我需要使用 hvplot 来开发交互式绘图。
region_cumulative_df_sel.hvplot(width=900)
很难查看 x 轴上的标签。如何将 xticks 更改为仅显示每个月的第一天,例如\"07-01\"、\"08-01\"、\"09-01\"、……、\"06-01\"?
我尝试了@Redox 代码如下:
region_cumulative_df_sel[\'Month-Day\'] = pd.to_datetime(region_cumulative_df_sel[\'Month-Day\'],format=\"%m-%d\") ##Convert to datetime
from bokeh.models.formatters import DatetimeTickFormatter
## Set format for showing x-axis ... you only need days, but in case counts change
formatter = DatetimeTickFormatter(days=[\"%m-%d\"], months=[\"%m-%d\"], years=[\"%m-%d\"])
region_cumulative_df_sel.plot(x=\'Month-Day\', xformatter=formatter, y=[\'RAIN_PERCENTILE_25\',\'RAIN_PERCENTILE_50\',\'RAIN_PERCENTILE_75\',\'RAIN_MEAN\',\'RAIN_MEDIAN\'], width=900, ylabel=\"Rainfall (mm)\",
rot=90, title=\"Cumulative Rainfall\")
这就是我生成的。
如何移动 x 轴上的 xticks 以与月日值对齐。此外,弹出窗口将“1900”显示为“月-日”列的年份。可以去掉年段吗?
标签: pandas holoviews hvplot holoviz-panel