1

我想为 julia 设置动画。无论如何,到目前为止一切正常,

我只需要更改轴标签。在绘制我的值时

x 轴和 y 轴都显示 500x500 的 linspace。我宁愿看

[-1,1]x[-1,1] 间隔定义了 linspace。我怎么能改变呢?

谢谢你 :)

代码:



import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

# Parameters and Test-Function
f = lambda z: z ** 2 - 0.1+0.651*1j
N = 1000
R = 2


def pre_greyscale(f, c, N, R):
    if np.abs(c) > R:
        return 0
    else:
        for i in range(0, N):
            c = f(c)
            if np.abs(c) > R:
                return i + 1
        return N


# fig1 = plt.figure()
real = np.linspace(-1, 1, num=500)
imaginary = np.linspace(-1, 1, num=500)
pre_image = np.empty(shape=(real.size, imaginary.size))

for k, r in enumerate(real):
    for p, i in enumerate(imaginary):
        pre_image[p, k] = pre_greyscale(f, r + i * 1j, N, R)


def animate(m):
    image = np.empty(shape=(real.size, imaginary.size))
    for k in range(0, 500):
        for p in range(0, 500):
            if pre_image[p, k] <= m:
                image[p, k] = 1 - pre_image[p, k] / m
            # else:
            #     image[k, p] = 0

    # mat = plt.imshow(image, cmap='gray')
    # plt.show()
    return image


imagelist = [animate(x) for x in range(N)]
fig = plt.figure()  # make figure

# Initialize imshow
im = plt.imshow(imagelist[0], cmap=plt.get_cmap('gray'), vmin=0, vmax=1)


# function to update figure
def updatefig(j):
    # set the data in the axesimage object
    im.set_array(imagelist[j])
    # return the artists set
    return [im]


# kick off the animation
ani = FuncAnimation(fig, updatefig, frames=N,
                    interval=20, blit=True)


ani.save('fractal2.gif', writer='pillow')

4

1 回答 1

1

添加范围参数plt.imshow将设置正确的标签:

# Initialize imshow
im = plt.imshow(imagelist[0], cmap=plt.get_cmap('gray'), vmin=0, vmax=1, extent=[-1,1,-1,1])

分形

于 2021-06-23T20:21:51.907 回答