GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • All
  • Best
  • Libs
  • Learn

This view

  • Original page
  • New address

GeezerVison is showing python-graph-gallery.com — Custom a Matplotlib Scatterplot

Custom a Matplotlib Scatterplot

logo of a chart:ScatterPlot

This post aims to provide a few elements of customization you can make to your scatter plot using the matplotlib library.

Scatterplot sectionAbout this chart

Marker Shape

Just use the marker argument of the plot() function to custom the shape of the data points. The code below produces a scatter plot with star shaped markers (figure on the left). The figure on the right shows you the possible shapes offered by python.

Custom a Matplotlib Scatterplot: Marker Shape

Custom a Matplotlib Scatterplot: Marker Shape (2)

# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
 
# dataset
df=pd.DataFrame({'x_values': range(1,101), 'y_values': np.random.randn(100)*80+range(1,101) })

# === Left figure:
plt.plot( 'x_values', 'y_values', data=df, linestyle='none', marker='*')
plt.show()
 
# === Right figure:
all_poss=['.','o','v','^','>','<','s','p','*','h','H','D','d','1','','']
 
# to see all possibilities:
# markers.MarkerStyle.markers.keys()
 
# set the limit of x and y axis:
plt.xlim(0.5,4.5)
plt.ylim(0.5,4.5)
 
# remove ticks and values of axis:
plt.xticks([])
plt.yticks([])
#plt.set_xlabel(size=0)
 
# Make a loop to add markers one by one
num=0
for x in range(1,5):
    for y in range(1,5):
        num += 1
        plt.plot(x,y,marker=all_poss[num-1], markerfacecolor='orange', markersize=23, markeredgecolor="black")
        plt.text(x+0.2, y, all_poss[num-1], horizontalalignment='left', size='medium', color='black', weight='semibold')

Marker Size

To change the marker size, just use the markersize argument:

Custom a Matplotlib Scatterplot: Marker Size

# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
 
# dataset
df=pd.DataFrame({'x_values': range(1,101), 'y_values': np.random.randn(100)*80+range(1,101) })

# scatter plot
plt.plot( 'x_values', 'y_values', data=df, linestyle='none', marker='D', markersize=16)
plt.show()
Dataviz caveat card: Beware of overplotting

⚠️ Avoid the 61 most common dataviz mistakes

The dataviz caveats I see the most, as a deck of 61 cards: a chart that is not ideal, and a better alternative. Free.

I respect your privacy. Unsubscribe anytime.

Marker Color

The color is controlled by the markerfacecolor and markeredgecolor arguments. There are several ways to call a color, see this dedicated page for more information.

Custom a Matplotlib Scatterplot: Marker Color

# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
 
# dataset
df=pd.DataFrame({'x_values': range(1,101), 'y_values': np.random.randn(100)*80+range(1,101) })

# scatter plot
plt.plot( 'x_values', 'y_values', data=df, linestyle='none', markerfacecolor='skyblue', marker="o", markeredgecolor="black", markersize=16)
plt.show()

Marker Edge

As you can control the marker edge color with the markeredgecolor argument, you can also control the marker width with the markeredgewidth argument.

Custom a Matplotlib Scatterplot: Marker Edge

# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
 
# dataset
df=pd.DataFrame({'x_values': range(1,101), 'y_values': np.random.randn(100)*80+range(1,101) })

# scatter plot
plt.plot( 'x_values', 'y_values', data=df, linestyle='none', marker='D', markersize=16, markeredgecolor="orange", markeredgewidth=5)
plt.show()

Related posts

Use categorical variable to color scatterplot in seaborn

Use categorical variable to color scatterplot in seaborn

Control Axis Limits of Plot

Control Axis Limits of Plot

Control Color of Each Marker

Control Color of Each Marker

Add text annotation on scatterplot

Add text annotation on scatterplot

Introduction to scatter plot with pandas

Introduction to scatter plot with pandas

Customizing Scatter Plots with Pandas

Customizing Scatter Plots with Pandas

Related chart types

logo of a chart:ScatterPlot

Scatterplot

logo of a chart:Heatmap

Heatmap

logo of a chart:Correlogram

Correlogram

logo of a chart:BubblePlot

Bubble

logo of a chart:ScatterConnected

Connected Scatter

logo of a chart:2dDensity

2D Density

300 projects

💡 Out of dataviz inspiration?

I have spent years collecting the most beautiful data visualizations out there. Get the list of my top 300 dataviz projects, hand-picked, for free.

I respect your privacy. Unsubscribe anytime.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.