ggraann
ggraann

Reputation: 35

How to make a scatter plot with different variables

Let's say I have a equation y=a*x, where a=[1,2,3,4] and x,y each have a set of values.

I get that for a simple x vs y plot plt.scatter(x,y) is enough, but how can I make a scatter plot of x vs y for each a?

Upvotes: 0

Views: 510

Answers (1)

dasJulian
dasJulian

Reputation: 577

This will create a list of axis objects and then it will make a scatterplot to each of them. I imported numpy in order to multiply the lists, which are now numpy arrays.

import matplotlib.pyplot as plt
import numpy as np

x = np.array([1, 2, 4])
y = np.array([4, 5, 2])
a = np.array([1, 5, 2])


#create the axis objects
fig, axis = plt.subplots(1, len(a))

for i in range(len(a)):
    axis[i].scatter(x, y * a[i])

Upvotes: 1

Related Questions