Wednesday, February 17, 2021

scatterplot

scatterplot

Scatter plot

This post gives a template for scatter plot in Python with two sets of points and two color-bars.

import matplotlib.pyplot as plt

# Generate data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y0 = [250, 32, 130, 300, 67, 120, 180, 50, 200]
y1 = [240, 23, 170, 250, 65, 130, 150, 60, 210]
c0 = [item/200. for item in y0]
c1 = [item/200. for item in y1] 

# Scatter plot
f, ax = plt.subplots()
ax0=ax.scatter(x, y0, s=200, c=c0, cmap='Blues', marker="o")
ax1=ax.scatter(x, y1, s=200, c=c1, cmap='Reds', marker="^")
plt.colorbar(ax0)
plt.colorbar(ax1)
plt.show()

Popular Posts