Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change scatter plot marker thickness

How can you change the thickness of marker lines in a scatter plot plt.scatter()? markeredgewidth is a valid attribute in plt.plot(); is there any equivalent attribute for scatter plots?

For example, when you change the size of a scatter plot (with marker = 'x'), the markers only get bigger, but the line thickness doesn't change.

I'm not trying to change the size but line thickness!

like image 632
Curtis Avatar asked Apr 08 '16 11:04

Curtis


People also ask

What is marker size in scatter?

Where, s is a scalar or an array of the same length as x and y , to set the scatter marker size. The default scatter marker size is rcParams['lines. markersize'] ** 2 . According to documentation, s is the marker size in points2.


2 Answers

you are looking for the kwarg linewidths. e.g.:

import matplotlib.pyplot as plt
import numpy as np
x = y = np.arange(5)

fig,ax = plt.subplots(1)

ax.scatter(x,y,  s=100,marker='x',color='b',linewidths=1)
ax.scatter(x,y+1,s=100,marker='x',color='r',linewidths=2)
ax.scatter(x,y+2,s=100,marker='x',color='g',linewidths=3)

plt.show()

Note: On some versions of matplotlib, it appears the kwarg is linewidth, not linewidths, despite what the manual currently says (April 2020). This is a known issue on the matplotlib github.

enter image description here

like image 57
tmdavison Avatar answered Oct 17 '22 23:10

tmdavison


In Ubuntu-18.04 and installed matplotlib==3.2.0 with python-3.6.9, you just need to set linewidth attribute (Not linewidths):

import matplotlib.pyplot as plt
import numpy as np
x = y = np.arange(5)

fig,ax = plt.subplots(1)

ax.scatter(x,y,  s=100,marker='x',color='b',linewidth=1)
ax.scatter(x,y+1,s=100,marker='x',color='r',linewidth=2)
ax.scatter(x,y+2,s=100,marker='x',color='g',linewidth=6)

plt.show()

enter image description here

like image 45
Behzad Sezari Avatar answered Oct 17 '22 21:10

Behzad Sezari