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. 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. 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. Traces of most types can be optionally associated with a single legend item in the legend. legend_elements ( ** kw ), loc = "lower right", title = "Price" ) plt. cmap ( 0.7 ), fmt = "$ ", func = lambda s : np. kw = dict ( prop = "sizes", num = 5, color = scatter. Note how we target at 5 elements here, but obtain only 4 in the # created legend due to the automatic round prices that are chosen for us. The *fmt* ensures to show the price # in dollars. Because we want to show the prices # in dollars, we use the *func* argument to supply the inverse of the function # used to calculate the sizes from above. add_artist ( legend1 ) # Produce a legend for the price (sizes). legend_elements ( num = 5 ), loc = "upper left", title = "Ranking" ) ax. Even though there are 40 different # rankings, we only want to show 5 of them in the legend. scatter ( volume, amount, c = ranking, s = 0.3 * ( price * 3 ) ** 2, vmin =- 3, vmax = 3, cmap = "Spectral" ) # Produce a legend for the ranking (colors). subplots () # Because the price is much too small when being provided as size for ``s``, # we normalize it to some useful point sizes, s=0.3*(price*3)**2 scatter = ax. uniform ( 1, 10, size = 40 ) fig, ax = plt.
0 Comments
Leave a Reply. |