如何改善使用matplotlib制作的Julia套装的不良视觉效果?

Stu*_*e75 2 python numpy matplotlib fractals python-2.7

如果你运行我在下面包含的代码(python 2.7),你会发现结果图像是黑暗和模糊的,几乎看起来有条纹在它上面运行.我意识到使用分散函数绘制这样的东西可能是滥用功能.

我仔细阅读了文档并迷失在其中,只是希望有人能告诉我如何让我的Julia套装看起来像你在书本和网上看到的漂亮的彩色印版一样漂亮.

import numpy as np
import matplotlib.pyplot as plt

# Plot ranges
r_min, r_max = -2.0, 2.0
c_min, c_max = -2.0, 2.0

# Even intervals for points to compute orbits of
r_range = np.arange(r_min, r_max, (r_max - r_min) / 200.0)
c_range = np.arange(c_min, c_max, (c_max - c_min) / 200.0)

c = complex(-0.624, 0.435)
xs = []
ys = []
colors = []

for comp in c_range:
    for real in r_range:
        z = complex(real, comp)

        escaped = False
        for i in range(0, 50):
            z = z*z + c

            if abs(z) > max(abs(c), 2):
                escaped = True

                # Colors correspond to escape speed
                if i < 7:
                    colors.append((1.0 - .055* i, 0.0, 0.0))

                if i >= 7 and i < 14:
                    colors.append((1.0 - .025*i, .6 - .025*i, 0))

                if i >= 14 and i < 21:
                    colors.append((1.0 - .0035*i, 1.0 - .0045*i, 0.0))

                if i >= 21 and i < 28:
                    colors.append((0.0, 1.0 - .0045*i, 0.0))

                if i >= 28 and i < 35:
                    colors.append((0.0, 0.0, 1.0 - .0055*i))

                if i >= 35 and i < 42:
                    colors.append((.435 - .0055*i, 0.0, 1.0 - .0055*i))    

                if i >= 42:
                    colors.append((0.62 - .005*i, 0, 1.0 - .005*i))
                break


        xs.append(real)
        ys.append(comp)

        # Points that don't escape are black
        if escaped == False:
            colors.append((0.0, 0.0, 0.0))

plt.axis([-2, 2, -2, 2])
plt.xlabel('x0')
plt.ylabel('c')
plt.scatter(xs, ys, c = colors, alpha = .2)
plt.show()
Run Code Online (Sandbox Code Playgroud)

编辑:以上是上述结果 - https://imgur.com/bdtZGVh

and*_*rew 5

有三种主要方法可以改善这种情节:

1 - 代替散点图,创建N×N矩阵,其中每个点的值确定该点的颜色.然后用plt.imshow(...)

2 - 使用不同的colormap(plt.imshow(...cmap="RdGy"))进行实验

3 - 增加点数以提高清晰度.也就是说,增加分母中的语句定义c_ranger_range

我已编辑您的代码以实现这些更改.寻找# CHANGED评论.新的数字看起来更好.

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

# Plot ranges
r_min, r_max = -2.0, 2.0
c_min, c_max = -2.0, 2.0

# Even intervals for points to compute orbits of
# CHANGED
r_range = np.arange(r_min, r_max, (r_max - r_min) / 500.0)
c_range = np.arange(c_min, c_max, (c_max - c_min) / 500.0)

c = complex(-0.624, 0.435)
xs = []
ys = []
# CHANGED
mat = np.zeros((len(c_range),len(r_range)))
colors = []

# CHANGED
matComp = 0 # Index of the new mat values
matReal = 0
for comp in c_range:
    for real in r_range:
        z = complex(real, comp)

        escaped = False
        for i in range(0, 50):
            z = z*z + c

            if abs(z) > max(abs(c), 2):
                escaped = True
                # CHANGED
                mat[matComp, matReal]=i

                # Colors correspond to escape speed
                if i < 7:
                    colors.append((1.0 - .055* i, 0.0, 0.0))

                if i >= 7 and i < 14:
                    colors.append((1.0 - .025*i, .6 - .025*i, 0))

                if i >= 14 and i < 21:
                    colors.append((1.0 - .0035*i, 1.0 - .0045*i, 0.0))

                if i >= 21 and i < 28:
                    colors.append((0.0, 1.0 - .0045*i, 0.0))

                if i >= 28 and i < 35:
                    colors.append((0.0, 0.0, 1.0 - .0055*i))

                if i >= 35 and i < 42:
                    colors.append((.435 - .0055*i, 0.0, 1.0 - .0055*i))    

                if i >= 42:
                    colors.append((0.62 - .005*i, 0, 1.0 - .005*i))
                break
        # CHANGED
        matReal += 1


        xs.append(real)
        ys.append(comp)

        # Points that don't escape are black
        if escaped == False:
            colors.append((0.0, 0.0, 0.0))
    # CHANGED
    matComp+=1
    matReal=0

#CHANGED
fig = plt.figure(figsize=(15,15))
plt.imshow(mat, cmap="RdGy", extent=[-2,2,-2,2])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述