Optionally one can include argument to both the linestyle and marker parameters. To specify the markerstyle you can include this as a positional argument in the method call, as seen in the example below. To plot a scatter in 3D, use the plot method, as the legend does not support Patch3DCollection as is returned by the scatter method of an Axes3D instance. Ho = plt.scatter(random(10), random(10), marker='x', color=colors) Hh = plt.scatter(random(10), random(10), marker='o', color=colors) H = plt.scatter(random(10), random(10), marker='o', color=colors) L = plt.scatter(random(10), random(10), marker='o', color=colors)Ī = plt.scatter(random(10), random(10), marker='o', color=colors) Ll = plt.scatter(random(10), random(10), marker='o', color=colors) Lo = plt.scatter(random(10), random(10), marker='x', color=colors) In the code below I've used random values rather than plotting the same range over and over, making all the plots visible (i.e. Also, if you are using scatter plots, use scatterpoints=1 rather than numpoints=1 in the legend call to have only one point for each legend entry. Using the scatter method of the matplotlib.pyplot module should work (at least with matplotlib 1.2.1 with Python 2.7.5), as in the example code below. When I run this, the legend no longer exists, it is a small white box in the corner with nothing in it. Plt.legend((lo,ll,l,a, h, hh, ho),('Low Outlier', 'LoLo','Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'),scatterpoints=1, loc='lower left', ncol=3, fontsize=8) Ho = plt.scatter(xHOutlier, yHOutlier, zHOutlier, marker='x', color=colors) Hh = plt.scatter(xHiHi, yHiHi, zHiHi, marker='o',color=colors) H = plt.scatter(xHi, yHi, zHi, marker='o',color=colors) L = plt.scatter(xLo, yLo, zLo, marker='o',color=colors)Ī = plt.scatter(xAverage, yAverage, zAverage, marker='o',color=colors) Ll = plt.scatter(xLoLo, yLoLo, zLoLo, marker='o', color=colors) lo = plt.scatter(xLOutlier, yLOutlier, zLOutlier, marker='x', color=colors) Each list contains either the x, y, or z variable. loc: represent the location of the legend. ncol: represent the number of columns in legend. With scatter, I changed the range(10) to the lists containing the data points. The syntax to add a legend to the plot: ( 'Title', ncol1, loc'upper left', bboxtoanchor (1,1)) The parameters used above are described below: title: specify the label you want to add. Scatter returned an error and scatter changed the graph and returned an error. I tried changing Line2D to Scatter and scatter. Plt.legend((lo,ll,l,a, h, hh, ho),('Low Outlier', 'LoLo','Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'),numpoints=1, loc='lower left', ncol=3, fontsize=8) When I create the legend, the legend shows the correct symbol and color but adds a line through it. I am trying to give specific names to the colors in the legend in the line "plt.legend()", but the problem is that it only gives name to the regression line, blue dots, red dots even though I have more (and different colors).I created a 4D scatter plot graph to represent different temperatures in a specific area. Plt.title('Expected goals vs position on table')Ĭolors = Īx.scatter(p, x, c=Alle.map(colors)) I have added a regression-line and made it so the dots for each league has a different color, but I am having some trouble with adding a legend to explain which league each color represents.Īx.set_yticks(np.arange(x.min()-26.53, x.max(), 10.0))Īx.set_xticks(np.arange(p.min(), p.max()+1, 1.0)) I'm trying to create a scatterplot-graph showing the relationship between xG and position on the table over several seasons in three different european football/soccer leagues.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |