Is it possible to turn off "corner rounding" when using
plot in matplotlib?
- I am trying to present a complicated nonsmooth function in a presentation.
- As a default (understandably) matplotlib rounds corners. (This is especially visible when the linewidth is increased.)
- I need more linewidth so the plot can be seen when the figure is projected.
import numpy as np import matplotlib.pyplot as plt x = np.linspace(-1, 1, 1001) y = abs(x) plt.plot(x, y, linewidth=10) plt.show()
produces the image:
- Increasing the number of points in
xdoes not resolve this issue.
- Note that the point
x=0is included in the plot.
The plotted curve above appears rounded at
x=0 when the function is not.
You can specify a
plt.plot(x, y, linewidth=10, solid_joinstyle='miter')