gboffi
gboffi

Reputation: 25023

pyplot.plot() doesn't respect keyword arguments

In my preamble I have

import numpy as np
import numpy as np
import matplotlib.pyplot as plt
from cycler import cycler
plt.style.use([
    'seaborn-paper', {'axes.prop_cycle': (
        cycler('color', ['k'])*
        cycler('lw', [2,1])*
        cycler('dashes', [[],[13,2],[8,3,1,3]]))}])

When I later use plt.plot() using keyword arguments (or their equivalents), e.g.,

a = np.array((0.,5.))
plt.plot(a,a, linewidth=6)
plt.plot(-a,a, '-')

I'm expecting a VERY wide 1st line and a continuous 2nd one, but this is what I get

the wrong line types!

What can I do if I want to

  1. have a sensible (for me:) default cycle for the line styles and
  2. break the rules here and there?

tia

Upvotes: 0

Views: 204

Answers (1)

tacaswell
tacaswell

Reputation: 87376

The issue as that the aliases for linewidth are not being properly de-aliased (so both linewidth and lw are being used to set the width and conflicting). A similar thing is happening with the style string vs linestyle vs dashes.

import numpy as np
import numpy as np
import matplotlib.pyplot as plt
from cycler import cycler
plt.style.use([
    'seaborn-paper', {'axes.prop_cycle': (
        cycler('color', ['k'])*
        cycler('linewidth', [2,1])*
        cycler('dashes', [[],[13,2],[8,3,1,3]]))}])

a = np.array((0.,5.))
plt.plot(a,a, linewidth=6)
plt.plot(-a,a, dashes=[])

should work.

The first issue (the lw aliasing) is fixed in 2.x, but even using dashes is the cycle is now broken :(

https://github.com/matplotlib/matplotlib/issues/7426

Upvotes: 1

Related Questions