Control Marker Features


This post shows the customization you can apply to the markers such as changing the marker color, transparency, shape and size.

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 markers
  • alpha : opacity of the markers
  • s : 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()

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Contact & Edit

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D