11/29/2023 0 Comments Matplotlib scatter point size![]() When I was doing my 10000-line project I figure out a general solution to bypass it. You have two option of using scatter command with multiple colour in a single call.Īs pylab.scatter command support use RGBA array to do whatever colour you want īack in early 2013, there is no way to do so, since the command only support single colour for the whole scatter point collection. This answer is dedicate to endless passion for correcting the 2013 version of myself in 2015. But after that it is quite trivial.īecause present version of support assigning: array of colour name string, array of float number with colour map, array of RGB or RGBA. This question is a bit tricky before Jan 2013 and matplotlib 1.3.1 (Aug 2013), which is the oldest stable version you can find on matpplotlib website. The output gives you differnent colors even when you have many different scatter plots in the same subplot. ![]() The only piece of code that you need: #Now this is actually the code that you need, an easy fix your colors just cut and paste not you need ax.Ĭolormap = plt.cm.gist_ncar #nipy_spectral, Set1,PairedĬolorst = #Let's generate some random X, Y data X =. scatter with no error bars) you can also change the colours after that you have plotted them, this sometimes is easier to perform. If you have only one type of collections (e.g. Xs=X*nRows #use list multiplication for repetition I think the most elegant way is that suggesyted by do a loop making multiple calls to scatter.īut if for some reason you wanted to do it with just one call, you can make a big list of colors, with a list comprehension and a bit of flooring division: import matplotlibĬolors = matplotlib.cm.rainbow(np.linspace(0, 1, len(Ys)))Ĭs = for i in range(len(Ys)*len(X))] #could be done with numpy's repmat When you have a list of lists and you want them colored per list. The logic to handle both cases simultaneously is also straightforward (e.g., check if its an radii_array is an int/float and if so make it an array).The normal way to plot plots with points in different colors in matplotlib is to pass a list of colors as a parameter. My_polygon_scatter(axes,, , radius=.5, resolution=5, alpha=.5, color='k')ĮDIT for Griff: If you want to handle a different radius for each point, you can do something straightforward like: def my_circle_scatter_radii(axes, x_array, y_array, radii_array, **kwargs):įor (x, y, r) in zip(x_array, y_array, radii_array):Ĭircle = pylab.Circle((x,y), radius=r, **kwargs) My_polygon_scatter(axes,, , radius=.5, resolution=3, alpha=.5, color='g') My_circle_scatter(axes,, , radius=2, alpha=.5, color='b') Polygon = ((x,y), radius=radius, resolution=resolution, **kwargs) ''' resolution is number of sides of polygon ''' Square = pylab.Rectangle((x-size/2,y-size/2), size, size, **kwargs)ĭef my_polygon_scatter(axes, x_array, y_array, resolution=5, radius=0.5, **kwargs): If you need something with scatter plot like ability, you could do something like import pylabĭef my_circle_scatter(axes, x_array, y_array, radius=0.5, **kwargs):Ĭircle = pylab.Circle((x,y), radius=radius, **kwargs)ĭef my_square_scatter(axes, x_array, y_array, size=0.5, **kwargs): If you want to say draw circles that are a given size, you should use the circle command in pylab import pylabĬircle1 = pylab.Circle((0,0), radius=20, alpha=.5)Ĭircle2 = pylab.Circle((0.5,0.5), radius=20, alpha=.5) This size will be independent of the axes, as is the nature of a scatter plot (it doesn't make sense if you narrow in on a region in a scatter plot that the points get bigger). ![]() ![]() The pylab.scatter function takes a value size based on the size in points^2.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |