Reputation: 669
I am creating a graph which uses few summarised value to be shown on plot. I need my x-axis to be constant from 1 to 30, fix it. So when the horizontal bars come up it will always be less than or equal to 30.
import plotly.graph_objects as go
import pandas as pd
df_prev_weather_final_sum = pd.read_csv("/content/sample_data/weather_sum_sample.csv")
print(df_prev_weather_final_sum.head())
weather_fig = go.Figure(go.Bar(
x = df_prev_weather_final_sum["values"],
y = df_prev_weather_final_sum["index"],
orientation = 'h',
marker_color='indianred'
))
weather_fig.update_layout(
title={
'text': "Weather",
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
yaxis_title="Port-Shipper",
xaxis_title="Number of Days",
template = "plotly_dark")
weather_fig.show()
How I can make the 'number of days' axis fix?
Upvotes: 1
Views: 1283
Reputation: 120
You can configure the xaxis
range using update_xaxes
:
weather_fig.update_xaxes(range=[1,30], dtick=1)
Upvotes: 1