IPython’s creator, Fernando Perez, was at the time scrambling to finish his PhD, and let John know he wouldn’t have time to review the patch for several months. It was conceived by John Hunter in 2002, originally as a patch to IPython for enabling interactive MATLAB-style plotting via gnuplot from the IPython command line. Matplotlib is a multiplatform data visualization library built on NumPy arrays, and designed to work with the broader SciPy stack. Here's an easier way of doing this (source: here): import matplotlib.pyplot as pltĪx.We’ll now take an in-depth look at the Matplotlib tool for visualization in Python. Ho = plt.scatter(random(10), random(10), marker='x', color=colors,label='High Outlier') Hh = plt.scatter(random(10), random(10), marker='o', color=colors,label='HiHi') H = plt.scatter(random(10), random(10), marker='o', color=colors,label='Hi') L = plt.scatter(random(10), random(10), marker='o', color=colors,label='Lo')Ī = plt.scatter(random(10), random(10), marker='o', color=colors,label='Average') Ll = plt.scatter(random(10), random(10), marker='o', color=colors,label='LoLo') Lo = plt.scatter(random(10), random(10), marker='x', color=colors,label='Low Outlier') Other answers seem a bit complex, you can just add a parameter 'label' in scatter function and that will be the legend for your plot. Plt.legend(handles=scatter.legend_elements(), labels=classes) Scatter = plt.scatter(x, y, c=values, cmap=colors) If you are using matplotlib version 3.1.1 or above, you can try: import matplotlib.pyplot as pltįrom lors import ListedColormap Plt.legend(loc='upper left', numpoints=1, ncol=3, fontsize=8, bbox_to_anchor=(0, 0)) 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. Posted on Thursday, Decemby admin 2D scatter plot
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |