Hello Everyone,
i am using numpy array [3,10] to plot the line chart using plotly express. The problem is i am not able to rename the legend names which are ‘wide_variable_0’ (default) and so on, The line plot variable is driven by dropdown menu. i have already tried the ‘label’ property but its not working.
please find attached screenshot and demo code for referance .
Any suggestion would be appreciated on how can i change the default legend names.
Have a nice day ahead
import dash
import numpy as np
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objects as go
import plotly.express as px
app = dash.Dash(name)
line_plot = go.Figure()
app.layout = html.Div([
html.H1(‘Line Plot’),
html.Div(
dcc.Dropdown(
id='page-1-dropdown',
options=[{'label': i, 'value': i} for i in ['first','second','third']],
value='first'
)),
html.Div(
dcc.Graph(id='line-plot',
figure=line_plot))
])
@app.callback(dash.dependencies.Output(‘line-plot’, ‘figure’),
[dash.dependencies.Input(‘page-1-dropdown’, ‘value’)])
def display_page(value):
“”“using numpy [3,10] matrix to plot the line plot in which ‘x axis’ will be the first list from the array and other two will be the ‘Y axis’ from matrix”""
data = [np.random.rand(3, 10) for _ in range(4)]
first_data = data[0]
second__data = data[1]
third_data = data[2]
if value == 'first':
x_axis = [x for x in first_data[0]]
y_axis = [y for y in first_data[1:]]
fig = px.line(x=x_axis, y=y_axis)
return fig
elif value == 'second' :
x_axis = [x for x in second__data[0]]
y_axis = [y for y in second__data[1:]]
fig = px.line(x=x_axis, y=y_axis)
return fig
elif value == 'third' :
x_axis = [x for x in third_data[0]]
y_axis = [y for y in third_data[1:]]
fig = px.line(x=x_axis, y=y_axis)
return fig
if name == ‘main’:
app.run_server(debug=True, port = 8090)