0

I found a way to do this with colors, but I'm unsure if there's a way to do it for the style. Here's how it was done using colors Get default line colour cycle.

I tried doing the same thing, but switching color to linestyle, but it doesn't look like the cycler includes that.

cycle = plt.rcParams['axes.prop_cycle'].by_key()['linestyle'] did not work

jared
  • 4,165
  • 1
  • 8
  • 31
  • What line style cycle are you referring to? – jared Jul 20 '23 at 01:14
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 20 '23 at 13:32
  • A couple of days ago I posted an answer (I'd say an excellent answer), but I've received zero feedback from you. Do you have solved on your own? do you just don't care anymore? or have you found my solution satisfactory? – gboffi Jul 22 '23 at 19:35

1 Answers1

0

Get the current property cycle, create a new cycler object for the line styles, and define a new property cycle using a multiplication operator, that here means an outer product.

current_prop_cycle = plt.rcParams['axes.prop_cycle']

from cycler import cycler
style_cycler = cycler('linestyle', ["solid", "dotted", "dashed", "dashdot"])

new_prop_cycle = current_prop_cycle * style_cycler

Next, change the property cycle for a single subplot

ax.set_prop_cycle(new_prop_cycle)

or change the default for the rest of your script

plt.rc('axes', prop_cycle=new_prop_cycle)

ps — the cycler cycles on all the combinations of colors and line styles, with line styles changing faster, c1 s1, c1 s2, ..., c2 s1, ..., if you want c1 s1, c2 s1, ... simply invert the order of the outer product, that is not commutative.

gboffi
  • 22,939
  • 8
  • 54
  • 85