pyplot: UserWarning marker is redundantly defined by the ‘marker’ keyword argument

I am using

plt.plot_date([dates[index], dates[index]+timeD], [pivots[index],pivots[index]], linestyle = "-", linewidth=2, marker = ",", )

to draw some lines on a chart. This used to work, but now after doing some upgrades, a warning is displayed:

UserWarning: marker is redundantly defined by the 'marker' keyword argument and the fmt string "o" (-> marker='o'). The keyword argument will take precedence.
plt.plot_date([dates[index], dates[index]+timeD], [pivots[index],pivots[index]], linestyle = "-", linewidth=2, marker = ",", )

If I just omit marker = “,” , the warning disappears, but there are two dots at the beginning and end of the line which I don’t like.

What could I do to get rid of the warning without changing the plot?

Answer

plt.plot_date takes the keyword argument fmt, which is the matplotlib’s shorthand for defining the marker and linestyle.

If you do not provide that fmt kwarg, a default value is used: "o"

One option option would be to use fmt to define both your marker and linestyle, instead of using the marker and linestyle kwargs:

plt.plot_date([dates[index], dates[index]+timeD], [pivots[index],pivots[index]],
              fmt=",-", linewidth=2)

For more info on fmt, see the Notes at the bottom the docs for plt.plot; note that it appears that fmt is used slightly differently for plot_date and plot, in that it is always defined for plot_date, while it is optional for plot