Something is wrong between the connection between the legend symbol color and the scatter plot error bars. 1 Answer Sorted by: 4 The matplotlib scatter example that addresses this problem also uses a loop, so that is probably the intended usage: If your larger goal is to just make plotting and labeling categorical data more straightforward, you should consider Seaborn. The problem is that the colors in the plot symbols are completely different from the symbol colors in the legend. Now, here is the code: import numpy as npĭf2a = pd.DataFrame(np.random.rand(10,5), columns = list('ABCDE'))ĭf2a.insert(0,'x_var_plot',range(1,df2a.shape+1))ĭf2a_err = pd.DataFrame(np.random.rand(df2a.shape,df2a.shape-1), columns = ())ĭf2a_err.insert(0,'x_var_plot',range(1,df2a.shape+1))Ĭolors = iter(cm.rainbow(np.linspace(0, 1, df2a.shape)))įor col in ():Īx.errorbar(df2a, df2a, yerr=df2a_err, fmt='o')Īx.scatter(df2a, df2a, color=next(colors), label=col) A nice solution exist for the case of line plots: leg ax.legend () change the font colors to match the line colors: for line,text in zip (leg.getlines (), leg.gettexts ()): tcolor (line.getcolor ()) However. There are different colors for all the plotted y-values. I made a scatter plot with 3 different colors and I want to match the color of the symbol and the text in the legend. Plt.I have a scatter plot of multiple y-values for the same x-value, in matplotlib (python 2.7). For full control of which artists have a legend entry, it is possible to pass an iterable of legend artists followed by an iterable of legend labels respectively: ax.legend( line1, line2, line3, 'label1', 'label2', 'label3') 3. 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). I think the most elegant way is that suggesyted by. E.g.: import matplotlib.pyplot ( 1,2,3, 4,5,6,color red,green,blue) When you have a list of lists and you want them colored per list. The idea to make the legend is to create proxy artists (i.e. The normal way to plot plots with points in different colors in matplotlib is to pass a list of colors as a parameter. 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) Whereas plotly.express has two functions scatter and line, go.Scatter can be used both for plotting points (makers) or lines, depending on the value of mode. Y = np.array(,, ])Ĭolor = np.array(,]*3).transpose() # Can be other colours than b,g,r Scatter and line plots with go.Scatter¶ If Plotly Express does not provide a good starting point, it is possible to use the more generic go.Scatter class from aphobjects. 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. Playing with linewidth might give help to visualize the true and the. So, you could just iterate through all edge colors and plot them in a loop over the same plot. scatter accepts an array for either one of them, but not for both. For the different rows, I use different colours. pyplot.scatter allows for passing to c an array that corresponds to groups, which will then color the points based on those groups. The dots of regular scatter plots can have an interior color and an edge color. For each of the points of the scatterplot, I want to see in which column and which row they are. 1 Answer Sorted by: 4 In matplotlib, you can easily generate custom legends. 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 |