![]() |
Matplotlib 2 lines with different markers - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Matplotlib 2 lines with different markers (/thread-29680.html) |
Matplotlib 2 lines with different markers - medatib531 - Sep-15-2020 Hello, I want to create a matplotlib plot for 2 different lines, however I need the lines to have different markers. i.e. use 'x' as marker for line 1 and '^' as marker for line 2. I tried to use itertools.next() as I saw in some online suggestions but no luck, plot still appears with 'x' as marker for both lines. Can someone help? My MWE code and the resulted plot below: from matplotlib import pyplot as plt import itertools xlist = [5, 10, 15, 20, 25] ylist = [[0.260864, 0.238644], [0.514823, 0.473904], [0.764035, 0.714735], [1.021157, 0.950179], [1.2735940000000001, 1.186469]] labelList = ["Line1","Line2"] fig, ax1 = plt.subplots() markers = itertools.cycle(['x','^','v']) ax1.plot(xlist,ylist,linewidth=1,marker=next(markers)) ax1.set_xlabel('x axis') ax1.set_ylabel('y axis') plt.legend(labelList) plt.show() ![]() Solution: from matplotlib import pyplot as plt import itertools xlist = [5, 10, 15, 20, 25] ylist = [[0.260864, 0.238644], [0.514823, 0.473904], [0.764035, 0.714735], [1.021157, 0.950179], [1.2735940000000001, 1.186469]] labelList = ["Line1","Line2"] fig, ax1 = plt.subplots() markers = itertools.cycle(['x','^','v']) ax1.plot(xlist,[item[0] for item in ylist],linewidth=1,marker=next(markers)) ax1.plot(xlist,[item[1] for item in ylist],linewidth=1,marker=next(markers)) ax1.set_xlabel('x axis') ax1.set_ylabel('y axis') plt.legend(labelList) plt.show() |