MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / MandelbrotDisplay

Class MandelbrotDisplay

galleries/examples/event_handling/viewlims.py:29–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27# can actually see the increasing detail. A box in the left panel will show
28# the area to which we are zoomed.
29class MandelbrotDisplay:
30 def __init__(self, h=500, w=500, niter=50, radius=2., power=2):
31 self.height = h
32 self.width = w
33 self.niter = niter
34 self.radius = radius
35 self.power = power
36
37 def compute_image(self, xlim, ylim):
38 self.x = np.linspace(*xlim, self.width)
39 self.y = np.linspace(*ylim, self.height).reshape(-1, 1)
40 c = self.x + 1.0j * self.y
41 threshold_time = np.zeros((self.height, self.width))
42 z = np.zeros(threshold_time.shape, dtype=complex)
43 mask = np.ones(threshold_time.shape, dtype=bool)
44 for i in range(self.niter):
45 z[mask] = z[mask]**self.power + c[mask]
46 mask = (np.abs(z) < self.radius)
47 threshold_time += mask
48 return threshold_time
49
50 def ax_update(self, ax):
51 ax.set_autoscale_on(False) # Otherwise, infinite loop
52 # Get the number of points from the number of pixels in the window
53 self.width, self.height = ax.patch.get_window_extent().size.round().astype(int)
54 # Update the image object with our new data and extent
55 ax.images[-1].set(data=self.compute_image(ax.get_xlim(), ax.get_ylim()),
56 extent=(*ax.get_xlim(), *ax.get_ylim()))
57 ax.figure.canvas.draw_idle()
58
59
60md = MandelbrotDisplay()

Callers 1

viewlims.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…