You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frommatplotlib.patchesimportCircleimportmatplotlib.pyplotasplt# draw circle outside of unit square (default limits)c=Circle(xy=[3.0, 1.0], radius=0.5)
plt.gca().add_artist(c)
plt.show()
Use add_artist only for artists for which there is no dedicated "add" method
I agree that docs could be more explicit here. (And maybe the API is not that great in that we burden the "right" way of adding more specialized artists on the user).
Bug
In principle add_patch() should update the limits. However this does not happen on an empty plot. Only if we have plotted something else before the updates happen correctly.
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
ax = plt.gca()
ax.plot(0, 0, 'o') # update to include circle limits only happens if we have plotted this before.
# draw circle outside of unit square (default limits)
c = Circle(xy=[3.0, 1.0], radius=0.5)
ax.add_patch(c)
plt.show()
Use add_artist only for artists for which there is no dedicated "add" method; and if necessary, use a method such as update_datalim to manually update the dataLim if the artist is to be included in autoscaling.
I'm considering changing this, so that add_patch will automatically dispatch to the correct function. IMHO users should not have to care about which function to call for which artist.
In principle add_patch() should update the limits. However this does not happen on an empty plot. Only if we have plotted something else before the updates happen correctly.
This is very weird behavior. What's the reason for this?
Activity
timhoffm commentedon Jan 13, 2021
Usage (DOC, API)
You should use
add_patch()instead ofadd_artist().add_artist states:
I agree that docs could be more explicit here. (And maybe the API is not that great in that we burden the "right" way of adding more specialized artists on the user).
Bug
In principle
add_patch()should update the limits. However this does not happen on an empty plot. Only if we have plotted something else before the updates happen correctly.QuLogic commentedon Jan 13, 2021
This is on purpose/known; from the docs:
timhoffm commentedon Jan 14, 2021
@QuLogic The docs are not very precise here: If you use
add_patch(), the limit updated is cared for (modulo the bug I've described above).nschloe commentedon Jan 14, 2021
I never realized that. So far, I've always used
add_artistand it seems to be quite common, too. (Seethe answers on https://stackoverflow.com/questions/9215658/plot-a-circle-with-pyplot.) I'll go ahead and spread the word.
timhoffm commentedon Jan 14, 2021
I'm considering changing this, so that
add_patchwill automatically dispatch to the correct function. IMHO users should not have to care about which function to call for which artist.tacaswell commentedon Jan 21, 2021
This may be fixed by #18216
gorogm commentedon Nov 1, 2022
Doesn't seem to be fixed by that :(
carlosgmartin commentedon Nov 10, 2025
This is very weird behavior. What's the reason for this?