Line_proxy = mlines.Line2D(,, color=line_color)Īxs. Scatter_proxy = mlines.Line2D(,, color='white', marker='o', markerfacecolor=scatter_color) Python, Machine Learning and Open Science are special areas of interest to me. H2 = axs.plot(x, y2, c=line_color, label='line') Unlike matplotlib, proplot adds outer colorbars and legends by allocating new rows and columns in the GridSpec rather than stealing space from the parent. Traces which are their own subplots (see above) do not. H1 = axs.scatter(x, y, c=scatter_color, label='scttr') Whether or not a given trace appears in the legend is controlled via the showlegend attribute. Make a Single Legend for All Subplots With figure.legend Method in Matplotlib import matplotlib.pyplot as plt fig plt.figure() axes fig.subplots(nrows2, ncols2) for ax in fig.axes: ax.plot(0, 10, 0, 10, label'linear') lines, labels () fig.legend(lines, labels, loc 'upper center') plt. I realise making the line color white is a bit hacky, but it was the best way I could find. One case where a custom legend might be desired is a scatter plot where a lot of different colors are used for a shape, but the user only wants one shape to. For example: ax.plot( 1, 2, 3) ax.plot( 5, 6, 7) ax.legend( 'First line', 'Second line') Parameters: handlessequence of Artist, optional A list of Artists (lines, patches) to be added to the legend. You create both using 2D but the one for the scatter plot has a white line (so isn't effectively seen) and has markers added to it. To make a legend for all artists on an Axes, call this function with an iterable of strings, one for each legend item. What you can do, instead, is create some different objects ( known as proxy artists) to fill the gap, so to speak.īelow are two proxy objects, scatter_proxy and line_proxy, for the scatter plot and line plot, respectively. import aphobjects as go from plotly.subplots import makesubplots fig makesubplots(rows2, cols2, startcell'bottom-left') fig.addtrace(go.Scatter(x1, 2, 3, y4, 5, 6), row1, col1) fig.addtrace(go.Scatter(x20, 30, 40, y50, 60, 70), row1, col2) fig.addtrace(go.Scatter(x300, 400, 500, y600, 700, 800), row2. The following also demonstrates how transparency of the markerscan be adjusted by giving alphaa value between 0 and 1. The issue is that you can't pass the Line objects directly to the legend call. To create a scatter plot with a legend one may use a loop and create onescatterplot per item to appear in the legend and set the labelaccordingly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |