Once you understood how to plot a basic scatterplot with seaborn, you might want to customize the appearance of your markers. You can customize color, transparency, shape and size of markers in your charts.
Control Marker Shape
In order to change the shape of the marker, you need to provide:
marker
: the shape of the marker (see list in the following section)
# library and dataset
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
# change shape of marker
sns.regplot(x=df["sepal_length"], y=df["sepal_width"], marker="+", fit_reg=False)
plt.show()
List of Available Marker Shapes
The matplotlib library has various marker shapes. You can check the possible shapes using markers function.
from matplotlib import markers # get all possible shapes all_shapes = markers.MarkerStyle.markers.keys() # print list of shapes all_shapes # ['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', '8', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_', 'P', 'X', # 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 'None', None, ' ', '']
Changing Color, Transparency and Size of Markers
You can also change the other features of markers in a plot. The following arguments must be provided:
color
: color of the markersalpha
: opacity of the markerss
: size of the markers
# library and dataset
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
# customize color, transparency and size of the markers
sns.regplot(x=df["sepal_length"], y=df["sepal_width"], fit_reg=False, scatter_kws={"color":"darkred","alpha":0.3,"s":200} )
plt.show()