0

I have 2 ndarrays A and B containing 3 columns each. Columns of A and B are corresponding and I would like to plot each corresponding column of A and B as lines in the same color, one dashed, one solid. I got this bit of code, but of course at the 2nd plot() command, pyplot continues w/ the next color in the color map:

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0, 10, 1)
A = np.array([[1] * 10, [5] * 10, [10] * 10])
B = np.array([[4] * 10, [20] * 10, [40] * 10])

plt.figure(1)
plt.plot(t, A.T, label=['A_1', 'A_2', 'A_3'])
plt.plot(t, B.T, linestyle='--', label=['B_1', 'B_2', 'B_3'])
plt.legend()
plt.show()

I would like to force pyplot.plot() to start over with the first color of the color map or any other nice way to achive the desired result. I could plot by iterating over the columns of both ndarrays and set specific colors for each iteration, but it seems to me there should be a shorter and more elegant solution. Any thoughts on that? Thanks!

chrizz
  • 43
  • 5
  • 1
    Is [this](https://stackoverflow.com/q/24193174/8881141) what you try to achieve? The matplotlib tutorials have a [section on cycler functions](https://matplotlib.org/stable/tutorials/intermediate/color_cycle.html). – Mr. T Dec 21 '21 at 13:40
  • 2
    @Mr. T : Thanks! inserting `plt.gca().set_prop_cycle(None)` between both `plot()` commands does the job. Sounds like it should be possible achieve it w/ a customized cycler as well... color cycler for columns and linestyle cycler for input arrays. Would feel like a cleaner way to me. Will try it out and post here if I can get it to work... – chrizz Dec 21 '21 at 13:57
  • You can readily change the cycler to iterate over line styles instead of colors. I think you can also have two cyclers and have one manually increment the color – Jody Klymak Dec 21 '21 at 14:13

0 Answers0