14

Say I am plotting a complex value like this:

a=-0.49+1j*1.14
plt.polar([0,angle(x)],[0,abs(x)],linewidth=5)

Giving

enter image description here

Is there a setting I can use to get rounded line ends, like the red line in the following example (drawn in paint)?

enter image description here

Lee
  • 29,398
  • 28
  • 117
  • 170

1 Answers1

31

The line proprty solid_capstyle (docs). There is also a dash_capstyle which controls the line ends on every dash.

import matplotlib.pyplot as plt
import numpy as np

x = y = np.arange(5)

fig, ax = plt. subplots()

ln, = ax.plot(x, y, lw=10, solid_capstyle='round')
ln2, = ax.plot(x, 4-y, lw=10)
ln2.set_solid_capstyle('round')
ax.margins(.2)

enter image description here

This will work equally will with plt.polar, which is a convenience method for creating a polar axes and calling plot on it, and the the Line2D object returned by it.

tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • 5
    To the OP, note that this will also work as a kwarg to `plt.polar`, as it just creates a polar axes and passes things on to `ax.plot`. For example: `plt.polar(x, y, linewidth=5, solid_capstyle='round')`. – Joe Kington May 19 '15 at 14:18
  • @JoeKington Fair enough, edited answer to include that comment. – tacaswell May 19 '15 at 14:27