python - Plotly:如何在 x 轴上仅绘制月份和日期? (忽略年份)

标签 python jupyter-notebook plotly jupyter

我正在尝试绘制时间序列数据,并希望 x 轴只是月和日。 Plotly 要求格式为 yyyy-mm-dd ,但我有几年数据集的每日平均值,所以我只想绘制 mm-dd在 x 轴上。当我发送的日期时间只是 mm-dd它假定 mm是年。能不能绕过年只拿mm-dd ?

df_en_ave1.index = df_en_ave1.index.strftime('%m-%d') #convert my index to month and day datetime

trace1=go.Scatter(x=df_en_ave1.index, y=df_en_ave1.evap) #need to bypass year in date here somehow

data = [trace1]

plotly.offline.iplot(data)

最佳答案

请尝试以下方式:

dcc.Graph(figure={
'data': [{
    'x': ['2015-01-01', '2015-01-10 15:30:12', '2015-04-01'],
    'y': [2, 1, 5]
}],
'layout': {
    'xaxis': {
        'tickformat': '%d/%m'
    }
}})

其他格式
%a - abbreviated weekday name.*
%A - full weekday name.*
%b - abbreviated month name.*
%B - full month name.*
%c - the locale's date and time, such as %x, %X.*
%d - zero-padded day of the month as a decimal number [01,31].
%e - space-padded day of the month as a decimal number [ 1,31]; equivalent to %_d.
%f - microseconds as a decimal number [000000, 999999].
%H - hour (24-hour clock) as a decimal number [00,23].
%I - hour (12-hour clock) as a decimal number [01,12].
%j - day of the year as a decimal number [001,366].
%m - month as a decimal number [01,12].
%M - minute as a decimal number [00,59].
%L - milliseconds as a decimal number [000, 999].
%p - either AM or PM.*
%Q - milliseconds since UNIX epoch.
%s - seconds since UNIX epoch.
%S - second as a decimal number [00,61].
%u - Monday-based (ISO 8601) weekday as a decimal number [1,7].
%U - Sunday-based week of the year as a decimal number [00,53].
%V - ISO 8601 week of the year as a decimal number [01, 53].
%w - Sunday-based weekday as a decimal number [0,6].
%W - Monday-based week of the year as a decimal number [00,53].
%x - the locale's date, such as %-m/%-d/%Y.*
%X - the locale's time, such as %-I:%M:%S %p.*
%y - year without century as a decimal number [00,99].
%Y - year with century as a decimal number.
%Z - time zone offset, such as -0700, -07:00, -07, or Z.
%{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46*
%% - a literal percent sign (%).

谢谢
https://community.plot.ly/t/how-to-make-the-messy-date-ticks-organized/7477/3

关于python - Plotly:如何在 x 轴上仅绘制月份和日期? (忽略年份),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52339903/

相关文章:

python - 从与我共享的文件夹中的 Google Drive 下载 zip 文件夹/文件

r - 使用 networkD3 在 R 中的 Sankey 图表中进行交互

python - 如何在python中实现多个构造函数?

python - db.create_all() 不创建在单独文件中定义的表

python - 将一个字典中的值与另一个字典中的键链接起来,并使用正则表达式在字符串中将一个替换为另一个

python - 在 Dash 中输入具有多个可移动值

python - Plotly:如何向子图添加边框和侧标签,并同步平移?

python - 如何解决函数问题同时允许其动态化?

anaconda - 如何摆脱 "set "JAVA_HOME_CONDA_BACKUP =""消息?

python - altair 删除或抑制自动生成的绘图图例