I’m working on a dash app project. I have a plot having 56 ticks on the X-axis. and need to show all the ticks. on a large screen, it shows all ticks separated, but when the screen size reduces xticks become congested.
it becomes congested when screen size reduces
I need help when screen size reduces it reduces the size of ticks. And show separated and clean ticks.
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# Generate x-values from 0 to 56
x_values = list(range(57))
# Sample data for y-values
y_values = [i for i in range(57)] # Sample y-values
# Create DataFrame
df = pd.DataFrame({'x': x_values, 'y': y_values})
# Create Dash app
app = dash.Dash(__name__)
# Define layout
app.layout = html.Div(children=[
# html.H1(children='Line Plot Example'),
dcc.Graph(
id='line-plot'
)
])
# Callback to update the plot
@app.callback(
Output('line-plot', 'figure'),
[Input('line-plot', 'id')]
)
def update_plot(_):
# Create trace using go.Scatter
trace = go.Scatter(x=df['x'], y=df['y'], mode='lines+markers', name='line')
# Create layout
layout = go.Layout(
title='Line Plot',
xaxis=dict(
title='X-axis',
tickvals=np.arange(57),
ticks="outside",
tickangle=0,
linewidth=1,
linecolor='black',
showline=True,
range=[0, max(df['x'])],
),
yaxis=dict(
title='Y-axis',
ticks="outside",
tickangle=0,
linewidth=1,
linecolor='black',
showline=True,
rangemode = "tozero",
),
paper_bgcolor='rgba(0,0,0,0)',
# plot_bgcolor='rgba(0,0,0,0)',
margin=dict(l=10, r=10, b=10, t=40)
)
# Create figure
fig = go.Figure(data=[trace], layout=layout)
return fig
if __name__ == '__main__':
app.run_server(debug=True)