0

I have a main plot and I'm trying to include a detail of a zoomed part in the same plot. Most of my tries end with the error: Can not reset the axes. You are probably trying to re-use an artist in more than one Axes which is not supported.

I've seen examples that work but none of them have an iteration for the subplot. Can somebody help me with this issue?

My code is very similar to this:

import matplotlib.pyplot as plt
import numpy.random as rnd
from matplotlib.patches import Ellipse

NUM = 250

ells = [Ellipse(xy=rnd.rand(2)*10, width=rnd.rand(), height=rnd.rand(), angle=rnd.rand()*360)
        for i in range(NUM)]

fig = plt.figure(0)
ax = fig.add_subplot(111, aspect='equal')
for e in ells:
    ax.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_alpha(rnd.rand())
    e.set_facecolor(rnd.rand(3))

ax.set_xlim(0, 10)
ax.set_ylim(0, 10)

#Subfigure
ax2 = plt.axes([.5, .3, .2, .2])

#I have to iterate in a subset of ells

plt.xticks([])
plt.yticks([])

plt.setp(ax2, xticks=[], yticks=[])

plt.show()
Amvd
  • 1
  • 2
  • Does this answer your question? [How to zoomed a portion of image and insert in the same plot in matplotlib](https://stackoverflow.com/questions/13583153/how-to-zoomed-a-portion-of-image-and-insert-in-the-same-plot-in-matplotlib) The second and third answer should work. – Joe Jun 11 '20 at 05:41
  • http://akuederle.com/matplotlib-zoomed-up-inset – Joe Jun 11 '20 at 05:42
  • I've already seen those examples but doesn't solve the problem. The problem is that I need to iterate to create the zoomed part and specifically, using "add_artist(e)" for a second time seems to be the not supported. – Amvd Jun 11 '20 at 14:01

0 Answers0