user13505457
user13505457

Reputation:

How to produce separate scatter plots for each data in python?

I have list of lists where each list represent as a feature vector :

Matrix=[[12,43,65,78,54,43,76,98],
[23,465,90,9,32,75,324,12],
[67,43,21,56,32,7,4,9],
[3,9,0,67,23,12,65,97]]

i also have another feature vector as fvector:

fvector=[54,76,12,55,88,75,32,3]

I want to plot a scatter plot for each list of a matrix with fvector separately but when i tried plotting by iterating over each list then it plots on the same graph:

I tried this:

import matplotlib.pyplot as plt
for i in Matrix:
    plt.scatter(i,fvector)

Output that i got is :

Output that i got is:

but i want each matrix plot separately ,and is it possible to plot small separate graphs ? Any reference or resource will be helpful.

Thanks

Upvotes: 0

Views: 3225

Answers (3)

HNMN3
HNMN3

Reputation: 542

You can use the subplots to create multiple plots on the same figure.

for i, item in enumerate(Matrix,1):
    plt.subplot(2, 2, i)
    plt.scatter(item, fvector)
plt.show()

If we have more than four lists in the Matrix then we can divide them into groups of four and generate separate figures for each set of 4 lists. Please check below:

for j in range(0, len(Matrix), 4):  
    for i, item in enumerate(Matrix[j:j+4],1):
        plt.subplot(2, 2, i)
        plt.scatter(item, fvector)
    plt.show()

Hope this helps!!

Upvotes: 1

sam
sam

Reputation: 2311

You need to use multiple axes using subplots

fig, ax = plt.subplots(2)

And the plot will look something like:

axs[0].plot(x1, y)
axs[1].plot(x2, y)

Upvotes: 0

Milan
Milan

Reputation: 344

for i in Matrix:
    plt.scatter(i,fvector)
    plt.show()

Should do it

Upvotes: 0

Related Questions