我正在通过plotly创建一个线图。我遇到了两个问题。Plotly默认显示x轴上的每7个值,并显示我的第一个x轴值的年份值(如屏幕截图所示)。下面是正在运行的代码。如果其中任何一个可以修复,那就太好了
from connect_to_db import get_df
import plotly.express as px
import os
df = get_df()
fig = px.bar(df, x='Date', y='Total', color='CUSTOMER_TYPE',
color_discrete_sequence=["#E15759","#8CD17D"], width=800, height=400)
fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)', 'paper_bgcolor': 'rgba(0, 0, 0, 0)', })
fig.update_layout(
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=.4))
fig.update_layout({
'legend_title_text': ''
},
xaxis_title="",
yaxis_title="Tested Count"
)
fig.update_xaxes(showline=True, linewidth=1, linecolor='#FBFBFB', mirror=False)
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor="#FBFBFB",showline=True, linewidth=2, linecolor='#FBFBFB', mirror=False)
fig.show()
谢谢大家
为了使年份消失,您只需为
xaxis_tickformat
制定另一个规范,如xaxis_tickformat = '%b'
即可获得:或者您可以选择
xaxis_tickformat = '%B'
并获得:在这两种情况下,年份都将根据您的请求删除
完整代码:
相关问题 更多 >
编程相关推荐