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?