0

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 ;) )

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks ! It's exactly what I want! But, can you explain this line : x_list = (x[i],) * len(y_list) ?
For a given station i, y_list is the set of measures (y-axis). They correspond to the point x[i]. The list x_list has to be the same size as y_list. So, the point x[i] has to be repeated len(y_list) times.
For instance: (1,) * 5 = (1, 1, 1, 1, 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.