Legend with Graph Objects

I want to create something like in Plot 1 here https://stackoverflow.com/questions/61892036/plotly-how-to-colorcode-plotly-graph-objects-bar-chart-using-python in vestland’s reply but using graph objects instead of plotly express as I need to use FigureWidget.

Basically, I want x-axis to be a column of continuous data, y-axis to be a column of categorical data, and the color to be another column of continuous data.

The problem is if you don’t use plotly express, the legend is not generated. While you can set “showlegend=True” and "marker_color=df[‘continuous_data’] , the legend is wrong as illustrated here:

Screenshot 2021-12-14 184055

  1. How do I use graph objects to generate a bar chart and legend similar to “Plot 1” in the stackoverflow reply by vestland?

  2. Or alternatively, is there is a way to use plotly express with FigureWidget?