Reputation: 53
I need to plot multiple graphs with different line colors and markers. I want number of graphs to be flexible and plot those automatically.
When I give and array of values to matplotlib.pyplot.plot to plot, it plots them with different colors. However, I couldn't find a way to also add markers on those plots.
import matplotlib.pyplot as plt
x_axis = [[252.7, 252.7, 252.7, 252.7, 252.7, 252.7],
[224.2, 224.2, 224.2, 224.2, 224.2, 224.2],
[198. , 198. , 198. , 198. , 198. , 198. ],
[179.2, 179.2, 179.2, 179.2, 179.2, 179.2],
[148.2, 148.2, 148.2, 148.2, 148.2, 148.2],
[124.7, 124.7, 124.7, 124.7, 124.7, 124.7],
[ 97.4, 97.4, 97.4, 97.4, 97.4, 97.4],
[ 81.3, 81.3, 81.3, 81.3, 81.3, 81.3],
[ 62.4, 62.4, 62.4, 62.4, 62.4, 62.4]]
y_axis = [[ 98.986099 , 100.165872 , 99.8226189, 100.563172 , 100.074811 ,
100.603689 ],
[ 99.9345974, 99.634039 , 100.126533 , 99.99223 , 100.264707 ,
100.165244 ],
[ 99.97628 , 100.174231 , 99.991863 , 99.9305726, 100.114646 ,
100.006637 ],
[ 99.8629142, 100.068743 , 99.7361936, 100.34242 , 99.9061321,
100.146376 ],
[ 99.9580146, 99.9585485, 100.064912 , 99.9304251, 100.135072 ,
100.044364 ],
[ 99.9656089, 100.022012 , 99.910529 , 100.054065 , 100.194655 ,
99.9474796],
[ 99.916351 , 100.05248 , 100.045002 , 99.8500087, 100.146954 ,
100.097336 ],
[ 99.8399431, 99.9708453, 100.040011 , 99.9784648, 100.05224 ,
100.262108 ],
[ 99.9390728, 100.003478 , 100.062155 , 99.9212035, 100.12125 ,
100.09437 ]]
plt.plot(x_axis,y_axis)
plt.show()
Plot I get plt.plot assigns different color to each graph, but the markers are not shown.
I would like to see the markers too, and I want to have different marker styles with the same color as the graphs line
I am new to python, please help!
Upvotes: 0
Views: 410
Reputation: 53
plt.plot(x, y, '-o')
did the job
Edit: in the argument '-o', '-' stands for solid line, 'o' stands for circle marker. Since x and y are arrays, and since there is no specification of color for markers and lines, python plots each graph in different color with solid line and circle marker.
Upvotes: 2