Setting markers in plot according to values in list
Say I have a list that looks like this:
list_a = [[1.2, 0.5, 3.1,...], [7.3, 1.5, 3.9,...], [100, 200, 150, ...]]
The first and second sub-lists in that list define my (x, y) values which
I want to plot. The third sub-list contains values associated to each (x,
y) point (say a certain property). These associated values can only be one
of three values: 100, 150, 200; which means that each (x, y) pair has
either a 100, a 150 or a 200value attached to it.
I want to plot these (x, y) points in a scatter plot but giving to each of
them a marker according to the values in this third list.
So, I'd want for example (not real code of course):
if list_a[2][item] == 100 then use marker = 'o' (circle marker)
if list_a[2][item] == 150 then use marker = 's' (square marker)
if list_a[2][item] == 200 then use marker = '^' (triangle_up marker)
The only way I can think of doing this is re-packaging list_a so that all
(x, y) pairs associated with the same value in the third list are moved to
its own list, like so:
list_100 =[[subset of x values], [subset of y values]]
list_150 =[[subset of x values], [subset of y values]]
list_200 =[[subset of x values], [subset of y values]]
and then plot each list separately, setting the appropriate marker each time:
plot.scatter(list_100[0], list_100[1], marker='o')
plot.scatter(list_150[0], list_150[1], marker='s')
plot.scatter(list_200[0], list_200[1], marker='^')
I'd like to know if there's a way of doing this without needing to
re-package the original list and then setting several separated plots for
each value in the third sub-list.
No comments:
Post a Comment