13

Essentially, I am trying to plot a vertical line at the axis position x=1 that has the -.k styling, however, it seems that I cannot use this kwarg within the axvline argument:

pyplot.axvline(x=1,ymin=0,ymax=0.35, '-.k')

Returns the error:

File "<ipython-input-70-04f296edd639>", line 7
    pyplot.axvline(x=1,ymin=0,ymax=0.35, '-.k')
SyntaxError: non-keyword arg after keyword arg

Hence, could someone advise me on what the correct kwarg is for this situation...

1 Answer 1

23

Is an image worth many words?

enter image description here

After the demonstrative image, I'd like to add that matplotlib.pyplot.axvline is a thin wrapper around matplotlib.axes.Axes.axvline, documented here.

The Axes.axvline method supports a large number of keyword arguments, of all of them two, as you have seen, are relevant to your question:

  1. color=..., the color argument is documented here and
  2. linestyle=..., the linestyle argument is documented here

To exemplify

import matplotlib.pyplot as plt
plt.plot((0,1,2,3))
plt.axvline(2, color='k', linestyle='--')

The keyword arguments here discussed of course apply also to the axhline method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.