Is there a way to reduce the number of ticks for the first x category x axis?
The code :
import calendar
import pandas as pd
from pathlib import Path
import plotly.graph_objects as go
import plotly.offline as pyo
import numpy as np
input_dataframe = pd.DataFrame(np.random.randn(8760, 3), index=pd.date_range(start='2023-01-01', periods=8760, freq='h'), columns=['Meas1', 'Meas2','Meas3'])
data_name = 'TestData'
column_aggregation_method = 'mean'
hourly_aggregation_hour_count = 3
if input_dataframe.shape[1] > 1:
if column_aggregation_method == 'mean':
input_dataframe = input_dataframe.mean(axis=1).rename(data_name).to_frame()
elif column_aggregation_method == 'min':
input_dataframe = input_dataframe.min(axis=1).rename(data_name).to_frame()
else:
input_dataframe = input_dataframe.max(axis=1).rename(data_name).to_frame()
grouped = input_dataframe.groupby([input_dataframe.index.year.rename('year'), input_dataframe.index.month.rename('month'), input_dataframe.index.hour.rename('hour')])
for col in input_dataframe.columns:
min_curve = grouped[col].apply(lambda x: x.nsmallest(hourly_aggregation_hour_count).mean())
mean_curve = grouped[col].apply(lambda x: x.mean())
max_curve = grouped[col].apply(lambda x: x.nlargest(hourly_aggregation_hour_count).mean())
min_curve_reset = min_curve.reset_index(level=[0,1,2])
min_curve_reset['month'] = min_curve_reset['month'].apply(lambda x: calendar.month_abbr[x])
min_curve_reset['month_year'] = min_curve_reset['month'] + " " + min_curve_reset['year'].astype(str)
fig = go.Figure()
fig.add_trace(go.Scatter(
x = [
list(min_curve_reset['month_year']),
list(min_curve_reset['hour'].astype(str))
],
y = list(min_curve_reset[data_name]),
line = dict(color='black'),name= 'Minimum'
))
fig.update_xaxes(
showgrid=True,
ticks="outside",
tickson="boundaries",
ticklen=20
)
fig.update_layout(showlegend=True)
pyo.plot(fig)