Python plot point size

matplotlib.pyplot.scatter#

matplotlib.pyplot. scatter ( 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 ) [source] #

A scatter plot of y vs. x with varying marker size and/or color.

Parameters : x, y float or array-like, shape (n, )

s float or array-like, shape (n, ), optional

The marker size in points**2 (typographic points are 1/72 in.). Default is rcParams[‘lines.markersize’] ** 2 .

c array-like or list of colors or color, optional

The marker colors. Possible values:

  • A scalar or sequence of n numbers to be mapped to colors using cmap and norm.
  • A 2D array in which the rows are RGB or RGBA.
  • A sequence of colors of length n.
  • A single color format string.

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. If you want to specify the same RGB or RGBA value for all points, use a 2D array with a single row. Otherwise, value-matching will have precedence in case of a size matching with x and y.

If you wish to specify a single color for all points prefer the color keyword argument.

Defaults to None . In that case the marker color is determined by the value of color, facecolor or facecolors. In case those are not specified or None , the marker color is determined by the next color of the Axes ‘ current «shape and fill» color cycle. This cycle defaults to rcParams[«axes.prop_cycle»] (default: cycler(‘color’, [‘#1f77b4’, ‘#ff7f0e’, ‘#2ca02c’, ‘#d62728’, ‘#9467bd’, ‘#8c564b’, ‘#e377c2’, ‘#7f7f7f’, ‘#bcbd22’, ‘#17becf’]) ).

The marker style. marker can be either an instance of the class or the text shorthand for a particular marker. See matplotlib.markers for more information about marker styles.

cmap str or Colormap , default: rcParams[«image.cmap»] (default: ‘viridis’ )

The Colormap instance or registered colormap name used to map scalar data to colors.

This parameter is ignored if c is RGB(A).

norm str or Normalize , optional

The normalization method used to scale scalar data to the [0, 1] range before mapping to colors using cmap. By default, a linear scaling is used, mapping the lowest value to 0 and the highest to 1.

Читайте также:  JavaScript Alert Box by PHP

If given, this can be one of the following:

  • An instance of Normalize or one of its subclasses (see Colormap Normalization ).
  • A scale name, i.e. one of «linear», «log», «symlog», «logit», etc. For a list of available scales, call matplotlib.scale.get_scale_names() . In that case, a suitable Normalize subclass is dynamically generated and instantiated.

This parameter is ignored if c is RGB(A).

vmin, vmax float, optional

When using scalar data and no explicit norm, vmin and vmax define the data range that the colormap covers. By default, the colormap covers the complete value range of the supplied data. It is an error to use vmin/vmax when a norm instance is given (but using a str norm name together with vmin/vmax is acceptable).

This parameter is ignored if c is RGB(A).

alpha float, default: None

The alpha blending value, between 0 (transparent) and 1 (opaque).

linewidths float or array-like, default: rcParams[«lines.linewidth»] (default: 1.5 )

The linewidth of the marker edges. Note: The default edgecolors is ‘face’. You may want to change this as well.

edgecolors None> or color or sequence of color, default: rcParams[«scatter.edgecolors»] (default: ‘face’ )

The edge color of the marker. Possible values:

  • ‘face’: The edge color will always be the same as the face color.
  • ‘none’: No patch boundary will be drawn.
  • A color or sequence of colors.

For non-filled markers, edgecolors is ignored. Instead, the color is determined like with ‘face’, i.e. from c, colors, or facecolors.

plotnonfinite bool, default: False

Whether to plot points with nonfinite c (i.e. inf , -inf or nan ). If True the points are drawn with the bad colormap color (see Colormap.set_bad ).

Returns : PathCollection Other Parameters : data indexable object, optional

If given, the following parameters also accept a string s , which is interpreted as data[s] (unless this raises an exception):

**kwargs Collection properties

To plot scatter plots when markers are identical in size and color.

  • The plot function will be faster for scatterplots where markers don’t vary in size or color.
  • Any or all of x, y, s, and c may be masked arrays, in which case all masks will be combined and only unmasked points will be plotted.
  • Fundamentally, scatter works with 1D arrays; x, y, s, and c may be input as N-D arrays, but within scatter they will be flattened. The exception is c, which will be flattened only if its size matches the size of x and y.

Источник

Читайте также:  Python django python path

pyplot scatter plot marker size

What kind of unit is points^2 ? What does it mean? Does s=100 mean 10 pixel x 10 pixel ? Basically I’m trying to make scatter plots with different marker sizes, and I want to figure out what does the s number mean.

matplotlib.pyplot.plot() has ms parameter ( markersize ) an equivalent for matplotlib.pyplot.scatter() parameter s ( size ). Just a reminder..

@neikas it seems to me they are not, since one is in pixels (markersize) and other is in this weird squared points unit (size). This has always been confusing to me, but I believe it has to do with scatterplot marker size being used to denote amount in a visually proportional way.

@heltonbiker is right on this one. If you want to match the markersize from the plot function to s from the scatter function, you need to square it, i.e. s = markersize**2 .

6 Answers 6

This can be a somewhat confusing way of defining the size but you are basically specifying the area of the marker. This means, to double the width (or height) of the marker you need to increase s by a factor of 4. [because A = WH => (2W)(2H)=4A]

There is a reason, however, that the size of markers is defined in this way. Because of the scaling of area as the square of width, doubling the width actually appears to increase the size by more than a factor 2 (in fact it increases it by a factor of 4). To see this consider the following two examples and the output they produce.

# doubling the width of markers x = [0,2,4,6,8,10] y = [0]*len(x) s = [20*4**n for n in range(len(x))] plt.scatter(x,y,s=s) plt.show() 

enter image description here

Notice how the size increases very quickly. If instead we have

# doubling the area of markers x = [0,2,4,6,8,10] y = [0]*len(x) s = [20*2**n for n in range(len(x))] plt.scatter(x,y,s=s) plt.show() 

enter image description here

Now the apparent size of the markers increases roughly linearly in an intuitive fashion.

As for the exact meaning of what a ‘point’ is, it is fairly arbitrary for plotting purposes, you can just scale all of your sizes by a constant until they look reasonable.

Edit: (In response to comment from @Emma)

It’s probably confusing wording on my part. The question asked about doubling the width of a circle so in the first picture for each circle (as we move from left to right) it’s width is double the previous one so for the area this is an exponential with base 4. Similarly the second example each circle has area double the last one which gives an exponential with base 2.

Читайте также:  Check permissions on file java

However it is the second example (where we are scaling area) that doubling area appears to make the circle twice as big to the eye. Thus if we want a circle to appear a factor of n bigger we would increase the area by a factor n not the radius so the apparent size scales linearly with the area.

Edit to visualize the comment by @TomaszGandor:

This is what it looks like for different functions of the marker size:

Exponential, Square, or Linear size

x = [0,2,4,6,8,10,12,14,16,18] s_exp = [20*2**n for n in range(len(x))] s_square = [20*n**2 for n in range(len(x))] s_linear = [20*n for n in range(len(x))] plt.scatter(x,[1]*len(x),s=s_exp, label='$s=2^n$', lw=1) plt.scatter(x,[0]*len(x),s=s_square, label='$s=n^2$') plt.scatter(x,[-1]*len(x),s=s_linear, label='$s=n$') plt.ylim(-1.5,1.5) plt.legend(loc='center left', bbox_to_anchor=(1.1, 0.5), labelspacing=3) plt.show() 

Источник

How to increase the size of scatter points in matplotlib ?

Examples of how to increase the size of scatter points in matplotlib:

Increase the size of all points

To increase the size of scatter points, a solution is to use the option «s» from the function scatter(), example

How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt x = [1,2,3,4,5,6,7,8] y = [4,1,3,6,1,3,5,2] plt.scatter(x,y,s=400,c='lightblue') plt.title('Nuage de points avec Matplotlib') plt.xlabel('x') plt.ylabel('y') plt.savefig('ScatterPlot_07.png') plt.show() 

Points with different size

To plot points with different size, a solution is to provide a list of size (or an array) to «s». Note that the list must be of the same size that the input data:

How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt x = [1,2,3,4,5,6,7,8] y = [4,1,3,6,1,3,5,2] size = [100,500,100,500,100,500,100,500] plt.scatter(x,y,s=size) plt.title('Nuage de points avec Matplotlib') plt.xlabel('x') plt.ylabel('y') plt.savefig('ScatterPlot_06.png') plt.show() 

Combining several scatter plots

Another solution is to combine multiple scatter plots:

How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt x = [1,2,3,4] y = [4,1,3,6] plt.scatter(x, y, s=100, c='coral') x = [5,6,7,8] y = [1,3,5,2] size = [100,500,100,500] plt.scatter(x, y, s=500, c='lightblue') plt.title('Nuage de points avec Matplotlib') plt.xlabel('x') plt.ylabel('y') plt.savefig('ScatterPlot_08.png') plt.show() 

References

Benjamin

Greetings, I am Ben! I completed my PhD in Atmospheric Science from the University of Lille, France. Subsequently, for 12 years I was employed at NASA as a Research Scientist focusing on Earth remote sensing. Presently, I work with NOAA concentrating on satellite-based Active Fire detection. Python, Machine Learning and Open Science are special areas of interest to me.

Skills

Источник

Оцените статью