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
Is there a setting I can use to get rounded line ends, like the red line in the following example (drawn in paint)?
The matplotlib. pyplot. plot() function by default produces a curve by joining two adjacent points in the data with a straight line, and hence the matplotlib.
The default linestyle while plotting data is solid linestyle in matplotlib. We can change this linestyle by using linestyle or ls argument of plot() method.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With