Phlegyas
Phlegyas

Reputation: 37

Python - plotting list of lists versus an other list

So, I have a list of stations (string) like this :

station_list=[station1, station2, station3, ..., station63]

And I have a list of lists with the measures of each stations, but they haven't the same number of measures. So, I have something like this :

measure_list=[[200.0, 200.0, 200.0, 200.0, 200.0, 300.0], [400.0, 400.0, 300.0, 300.0, 300.0, 300.0, 300.0, 300.0, 300.0], [300.0, 400.0, 400.0, 400.0, 400.0], ..., [1000.0, 1000.0, 1000.0, 1000.0, 1000.0], [7000.0]]

the measure_list have 63 "sub-list", a sub-list for each station.

Finally, I would like to create a graph with the stations on the x-axis and the measures on the y-axis for a comparison between all the station's measures.

Thanks for your help. (and sorry for my bad english ;) )

Upvotes: 0

Views: 1359

Answers (1)

Taha
Taha

Reputation: 778

I suggest following this example ...

Here is an adaptation with the result:

import numpy as np
import matplotlib.pyplot as plt

station_list=['station1', 'station2', 'station3', 'station63']
measure_list=[
    [200.0, 200.0, 200.0, 200.0, 200.0, 300.0],
    [400.0, 400.0, 300.0, 300.0, 300.0, 300.0, 300.0, 300.0, 300.0],
    [300.0, 400.0, 400.0, 400.0, 400.0],
    [1000.0, 1000.0, 1000.0, 1000.0, 1000.0],
    ]
x = range(len(station_list))

assert len(station_list) == len(measure_list) == len(x)

for i, label in enumerate(station_list):
    y_list = measure_list[i]
    x_list = (x[i],) * len(y_list)

    plt.plot(x_list, y_list, 'o')

# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, station_list, rotation='vertical')

# Pad margins so that markers don't get clipped by the axes
# plt.margins(0.2)
plt.xlim(np.min(x) - 0.5, np.max(x) + 0.5)

# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
plt.show()

Which gives: Result of the given example

Upvotes: 3

Related Questions