impedance.py icon indicating copy to clipboard operation
impedance.py copied to clipboard

[BUG] Matplotlib warnings when plotting Bode or Nyquist plot

Open momoson opened this issue 2 years ago • 1 comments

Describe the bug Matplotlib warnings occure when plotting the default Bode or Nyquist plot, like lib/python3.11/site-packages/impedance/visualization.py:39: UserWarning: linestyle is redundantly defined by the 'linestyle' keyword argument and the fmt string ".-" (-> linestyle='-'). The keyword argument will take precedence.

To Reproduce Open and execute the notebook docs/source/examples/plotting_example.ipynb.

Expected behavior No warnings

momoson avatar Jul 15 '23 20:07 momoson

I can reproduce this warning. This fixes the warning for me:

def plot_nyquist(Z, scale=1, units='Ohms', fmt='.-', ax=None, labelsize=20,
                 ticksize=14, **kwargs):
    ...
    # Fix warning for multiple values for formats.
    # fmt = '[marker][line][color]'
    if len(fmt) > 1:
        marker = kwargs.pop('marker', None)
        if marker is not None:
            fmt = marker + fmt[1:]
    color = kwargs.pop('color', None)
    if color is not None:
        fmt = fmt[:-1] + color
    linestyle = kwargs.pop('ls', None)
    if linestyle is not None:
        if color is not None:
            fmt = fmt[0] + linestyle + fmt[-1]
        else:
            fmt = fmt[:-1] + linestyle

This is reasonably ugly. Also, I haven't looked at all corner cases. So, a different approach may be better. matplotlib version: 3.8.4

pya avatar May 10 '24 07:05 pya