Thanks!!!
Could we think about it deeper??
I’d like to do with stacked bar chart
but I couldn’t have any clue…
I could get infomation which i clicked! like this (‘curveNumber’, ‘x’)
But!!! how can I highlight it at this case??
Could you give me advice again please?
{‘points’: [{‘curveNumber’: 2, ‘pointNumber’: 2, ‘pointIndex’: 2, ‘x’: ‘Canada’, ‘y’: 12, ‘label’: ‘Canada’, ‘value’: 12, ‘bbox’: {‘x0’: 740.4, ‘x1’: 988.93, ‘y0’: 223.66, ‘y1’: 223.66}}]}
from dash import Dash, html, dcc, Input, Output, Patch, callback
import plotly.graph_objects as go
import random
app = Dash(__name__)
# Creating some starter x and y data
long_df = px.data.medals_long()
# go방식
trace_gold = go.Bar(
x=long_df[long_df['medal'] == 'gold']['nation'],
y=long_df[long_df['medal'] == 'gold']['count'],
name='Gold',
marker=dict(color='gold')
)
trace_silver = go.Bar(
x=long_df[long_df['medal'] == 'silver']['nation'],
y=long_df[long_df['medal'] == 'silver']['count'],
name='Silver',
marker=dict(color='silver')
)
trace_bronze = go.Bar(
x=long_df[long_df['medal'] == 'bronze']['nation'],
y=long_df[long_df['medal'] == 'bronze']['count'],
name='Bronze',
marker=dict(color='#CD7F32') # Bronze color
)
# Create a stacked bar plot
fig = go.Figure(data=[trace_gold, trace_silver, trace_bronze])
# Update the layout for stacking bars
fig.update_layout(
barmode='stack', # Stack bars
title='Stacked Bar Plot of Medal Counts by Nation',
xaxis=dict(title='Nation'),
yaxis=dict(title='Count')
)
app.layout = html.Div(
[
html.Div("Updating Selected Bar Color"),
dcc.Graph(figure=fig, id="example-graph"),
]
)
@callback(
Output("example-graph", "figure"),
Input("example-graph", "clickData"),
prevent_initial_call=True,
)
def add_data_to_fig(data):
print(data)
patched_figure = Patch()
return patched_figure
if __name__ == "__main__":
app.run(debug=True)