Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Turn off corner rounding in matplotlib plot with thicker lines

Question:

Is it possible to turn off "corner rounding" when using plot in matplotlib?

Setup:

  • 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.

Example:

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:

absolute_value

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Attempts:

  • Increasing the number of points in x does not resolve this issue.
  • Note that the point x=0 is included in the plot.

Summary:

The plotted curve above appears rounded at x=0 when the function is not.

>Solution :

You can specify a JoinStyle:

plt.plot(x, y, linewidth=10, solid_joinstyle='miter')

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading