![]() ![]() 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" ), 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. 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. Plt.Traces of most types can be optionally associated with a single legend item in the legend. Rows = ) for i in range(3)]Ĭolumns =, , marker, markerfacecolor='w', ![]() Plt.scatter(x, y, c=color, marker=marker) Putting everything together: import numpy as np Proxy = plt.plot(,, 'o', markerfacecolor='w', markeredgecolor='k')Īnd the colored rectangles for the rows can be created with patches: The column markers can be obtained by plotting empty lines with: used only for the legend): plt.legend(list_of_proxy_artists, list_of_labels). The idea to make the legend is to create proxy artists (i.e. How can I also add the marker? And now in my legend, the first marker is green, while the other two are blue. Plt.scatter(x, y, c=color, marker=marker, label=label) Y = np.array(,, ])Ĭolor = np.array(,]*3).transpose() # Can be other colours than b,g,r Simplified my code looks something like this: x = np.array(,, ]) I managed to get the column in the legend, but not the row. In the legend I want the colours to indicate a number (corresponding to the row) and the markers to indicate a letter (corresponding to the column). For the different columns, I use different markers. For the different rows, I use different colours. For each of the points of the scatterplot, I want to see in which column and which row they are. I want to plot the values of two matrices in a scatter plot. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |