
# Extract uniques points so we can map an offset for each Effective offset for each point is `index of appearance` * offset Points (array-like (2D)): Array containing the pointsĬomponent_index (int): Index / column on which the offset will be applied """Dodge every point by a multiplicative offset (multiplier is based on frequency of appearance) import numpy as npĭef dodge_points(points, component_index, offset): I therefore came up with this function in order to offset identical points. My answer may not perfectly answer your question, however, I too tried to plot overlapping points, but mine were perfectly overlapped. c can be a 2-D array in which the rows are RGB or RGBA, however, including the case of a single row to specify the same color for all points. Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. I learnt this trick a while ago when I noticed the documentation of the scatter function - c : color or sequence of color, optional, default : 'b'Ĭ can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). Plt.scatter( samples, samples, color=colours ) Norm = Normalize( vmin=vals.min(), vmax=vals.max() )Ĭolours = Ĭolours = makeColours( densObj.evaluate( samples ) )
#Matplotlib scatter smaller dots code
To modify the code in the earlier example : import numpy as npįrom scipy.stats import gaussian_kde as kde The markersize is only the width (not the area) of the marker: ax.You could also colour the points by first computing a kernel density estimate of the distribution of the scatter, and using the density values to specify a colour for each point of the scatter. If even gets more confusing if you use plot (which is faster if all markers should have the same size as the docs state as "Notes"). #ax.plot(x_data, y_data, "o",markersize=2*r_)Īs soon as you add an edge (so a non-zero border around the markers), they will overlap: So calculating the area is not pi * r_**2 but rather a square: (2*r_)**2 # open figureĪx.scatter(x_data, y_data, s=marker_size,linewidths=1) one would never calculate the actual area of the symbol). We are not talking about the area of the symbol (in this case a circle) but of a bounding box of the marker (imagine, you want to control the size of a star or an asterix as marker. This is due a misunderstanding of the area of the markers.

This is a rather tedious idea, because you need to plot the data twice but you keep the autosizing of the axes. Scl = ax.get_xlim() - ax.get_xlim()Īx.scatter(x_data, y_data, s=marker_size/scl**2, edgecolors='blue',color='red') or scale the markers's size according to the new limits (you will need to know them or do the plotting again) # plot with invisible colorĪx.scatter(x_data, y_data, s=marker_size, color=(0,0,0,0))


R_ = ax.ansform() - ax.ansform() # points # create a n x n square with a marker at each point as dummy data The complete code is: import matplotlib.pyplot as plt So either set the limits to the known size before plotting: ax.set_xlim((0,n-1)) but you are not reducing the marker-size. The bottom line is that you determine the coordinate transformation with the default axis-limits ( (0,1) x (0,1)) and enlarges them afterwards to (-0.75, 15.75)x (-0.75, 15.75). Yes, the problem is that you determine the coordinate-units-to-figure-points size before plotting, so before setting the limits, which influence the coordinate-units but not the overall figure size. The radius is (almost) exactly the r=0.5 coordinate-units that you wanted to have.

You can see this if you plot just 4 points ( n=2): When I run it with s=r_ I get the result on the left and with s=marker_size I get the result on the right of the following image: R_ = ax.ansform() - ax.ansform()Īx.scatter(x_data, y_data, s=marker_size, edgecolors='black') # calculate the marker size so that the markers touch # create a n x n square with a marker at each point Here is an example code of what I want to accomplish, with the results as an image below the code: import matplotlib.pyplot as plt It could also be that running matplotlib from WSL via VcXsrv is causing this problem. I tried transforming the given radius into points via ansData and then calculating the area via pi * r^2, but I did not succeed. I've read in pyplot scatter plot marker size, that the marker size is given as the area of the marker in points^2. I want to have the markers of a scatter plot match a radius given in the data coordinates.
