4.2. Scatter Plot

4.2.1. Rationale

  • Used to show correlation

4.2.2. Syntax

import matplotlib.pyplot as plt


x = [1, 2, 3, 4]
y = [1, 2, 3, 4]

plt.scatter(x, y)
plt.show()

4.2.3. Simple Points

import matplotlib.pyplot as plt
import numpy as np


x = np.linspace(0, 10, 50)
y = np.sin(x)

plt.scatter(x, y)
plt.show()

4.2.4. Markers

  • marker

  • s - size

../_images/matplotlib-markers-filled.png
../_images/matplotlib-markers-unfilled.png
import matplotlib.pyplot as plt


x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [5, 2, 4, 2, 1, 4, 5, 2]

plt.scatter(x, y, marker='*', s=100)
plt.show()
import matplotlib.pyplot as plt
import numpy as np


x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [5, 2, 4, 2, 1, 4, 5, 2]

plt.scatter(x, y, marker='x', s=100)
plt.show()
import matplotlib.pyplot as plt
import numpy as np


x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [4, 7, 6, 2, 7, 4, 5, 2]

plt.scatter(x, y, marker='*', s=500)
plt.scatter(y, x, marker='o', s=500)

plt.show()