What is the difference between add_artist or add_patch
Asked Answered
S

0

7

I am trying to find the difference between add_artist method and add_patch but I can't figure out.

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
matplotlib.use('TkAgg')

fig, ax = plt.subplots()
ax.add_patch(Circle((0.5, 0.5), 0.3))

plt.show()

And

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
matplotlib.use('TkAgg')

fig, ax = plt.subplots()
ax.add_artist(Circle((0.5, 0.5), 0.3))

plt.show()

Give the exact same behaviour... Maybe these two methods are doing the same but I am not sure ? Which one do I need to use if I want to draw something ?

Kind regards,

Spalato answered 13/4, 2021 at 12:56 Comment(4)
add_artist isn't really intended for data, but for annotations to the data.Moron
So it's the same thing with a different name for a different goal ?Spalato
One difference I have come across is that add_patch changes the data limits where as add_artist does not. For example, if you increase the radius to 0.6 in your MWE, and call ax.autoscale_view() before plt.show(), then the x and y limits will be adjusted in the first plot but not in the second.Thuthucydides
Thanks for this answer.Spalato

© 2022 - 2024 — McMap. All rights reserved.