0

Given a list of lists I am tryuing to plot every row in a different color, but get error:

ValueError: x and y must be the same size

lists = 

    0     [[44.9597, 7.7825], [44.9646, 7.7816], [45.1206, 7.7115]]
    1     [[45.0021, 7.6733], [45.003, 7.6678]]
    2     [[45.0746, 7.5985], [45.0735, 7.5956],[44.9706, 7.704],[45.0811, 7.5511]
    3     [[45.1205, 7.7116]] 

So, in every row first number in [ ] is y and second number is x

I have tried matplotlib and seaborn

Mamed
  • 1,102
  • 8
  • 23
  • Can you give some more information? Are the x-values the index and the y-values the lists? Or are the x- and y-values in each list of lists? Might also help if you could provide a plot for maybe one of the rows so we know what you're trying to make – Ian Thompson Oct 06 '19 at 17:12
  • @IanThompson ok. So, in every row first number in `[ ]` is `y` and second number is `x` – Mamed Oct 06 '19 at 17:17

1 Answers1

2

You can use matplotlibs scatter(x,y) function along with numpy:

import numpy as np
import matplotlib.pyplot as plt

lists = np.array([[[44.9597, 7.7825], [44.9646, 7.7816], [45.1206, 7.7115]], \
                  [[45.0021, 7.6733], [45.003, 7.6678]], \
                  [[45.0746, 7.5985], [45.0735, 7.5956],[44.9706, 7.704],[45.0811, 7.5511]], \
                  [[45.1205, 7.7116]]])

plt.figure()
for l in lists:
    ar = np.array(l)  # convert to numpy array for use of indices in next line
    plt.scatter(ar[:,1], ar[:,0]) 
plt.show()

wohe1
  • 755
  • 7
  • 26