impedance.py
impedance.py copied to clipboard
[BUG] Matplotlib warnings when plotting Bode or Nyquist plot
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
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