12/4/2023 0 Comments Matplotlib scatter smaller dots![]() Each number in the list is the size of the marker in Scatter plot.Įxample.py import matplotlib. In the following example, we will draw a scatter plot with 6 (six) data points, and set specific size for the markers of these data points on the Scatter plot, with a list of numbers. Note: The length of the size list that we give for named parameter s, should be consistent with the lengths of x and y. It is an optional parameter and the default value is. (x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs) This parameter indicates the marker size (it can be scalar or array of size equal to the size of x or y). The following is definition of scatter() function with s parameter, at third position, whose default value is None. The markersize is only the width (not the area) of the marker: ax.To set specific size for markers in Scatter Plot in Matplotlib, pass required sizes for markers as list, to s parameter of scatter() function, where each size is applied to respective data point. 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) Since the markersize is given in points, one would need to use the figure dpi to calculate the size of one pixel in points. import matplotlib.pyplot as plt from numpy import pi n 16 create a n x n square with a marker at each point xdata ydata for x in range(n): for y in range(n): xdata.append(x) ydata.append(y) fig,ax plt.subplots(figsize7,7) important part: calculate the marker size so that the markers touch radius in data coordinates. one would never calculate the actual area of the symbol). The solution is to use a usual 'o' or 's' marker, but set the markersize to be exactly one pixel. 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. I can get exactly what I want using gnuplot: plot 'nodes' with points. When the markers are small, only the line is visible, not the fill, and the line isn't the right colour (it's always black). The problem is that the scatter () function's markers seem to have both a line and a fill. The radius is (almost) exactly the r=0.5 coordinate-units that you wanted to have. Because of the point density, the points need to be small. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |