Python scatter plot multiple color legend12/14/2023 ![]() ![]() update_layout ( legend = dict ( groupclick = "toggleitem" )) fig. update_layout ( title = "Try Clicking on the Legend Items!" ) fig. Scatter ( x =, y =, legendgroup = "group2", name = "second legend group - average", mode = "lines", line = dict ( color = "MediumPurple" ) )) fig. Scatter ( x =, y =, legendgroup = "group2", legendgrouptitle_text = "Second Group Title", name = "second legend group", mode = "markers", marker = dict ( color = "MediumPurple", size = 10 ) )) fig. Scatter ( x =, y =, legendgroup = "group", name = "first legend group - average", mode = "lines", line = dict ( color = "Crimson" ) )) fig. Scatter ( x =, y =, legendgroup = "group", # this can be any string, not just "group" legendgrouptitle_text = "First Group Title", name = "first legend group", mode = "markers", marker = dict ( color = "Crimson", size = 10 ) )) fig. Scatter ( x =, y =, legendgroup = "group2", name = "second legend group - average", mode = "lines", line = dict ( color = "MediumPurple" ), showlegend = False )) fig. Scatter ( x =, y =, legendgroup = "group2", name = "second legend group", mode = "markers", marker = dict ( color = "MediumPurple", size = 10 ) )) fig. Scatter ( x =, y =, legendgroup = "group", name = "first legend group - average", mode = "lines", line = dict ( color = "Crimson" ), showlegend = False, )) fig. Scatter ( x =, y =, legendgroup = "group", # this can be any string, not just "group" name = "first legend group", mode = "markers", marker = dict ( color = "Crimson", size = 10 ) )) fig. ![]() Alternatively, color axes can be configured within the trace itself. Color axes have a legend-like component called color bars. Multiple traces can be linked to the same color axis. ![]() Traces which support continuous color can also be associated with color axes in the layout via the coloraxis attribute. Plotly Express has robust support for discrete color to make this easy. The fact that legend items are linked to traces means that when using discrete color, a figure must have one trace per color in order to get a meaningful legend. Traces that support legend items also support the legendgroup attribute, and all traces with the same legend group are treated the same way during click/double-click interactions. Users may show or hide traces by clicking or double-clicking on their associated legend item. Traces which are their own subplots (see above) do not support this, with the exception of traces of type pie and funnelarea for which every distinct color represented in the trace gets a separate legend item. Whether or not a given trace appears in the legend is controlled via the showlegend attribute. Plotįig.add_traces(go.Scatter(x=.iloc], y=.Traces of most types can be optionally associated with a single legend item in the legend. In the figure below, the marker is blue if both pass, red if both fail, and a red circle with a blue dot (or the opposite) if one passes and one fails. I would consider go.Scatter() instead of px.scatter(), and then use two different symbols with two different colors. But that doesn't mean it's impossible to visualize the story your aiming to tell here. I don't think there's a very straight-forward to do that. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |