2016-12-26 9 views
1

matplotlib를 사용하여 Mandelbrot을 플로팅하려합니다. 한 가지 색상으로 해봤지만, 이제는 반복 횟수에 따라 cmap을 넣으려고합니다. 내가 plt.scatter에서 C, VMIN과 VMAX를 정의하는 방법을 잘 모르겠습니다matplotlib의 Cmap

import random 
import matplotlib.pyplot as plt 


elem = 10000 
x = [] 
y = [] 
colors = [] 

def iteration(x): 
    n = 0 
    result = 0 
    while n < 1000: # max iterations 
     result = pow(result, 2) + c 
     if abs(result) > 2: 
      return n   
     n += 1 
    return n 

for i in range(elem): 
    c = complex(random.uniform(-2.5,1),random.uniform(-1.5,1.5)) 
    x.append(c.real) 
    y.append(c.imag) 
    colors.append(iteration(c)) 


plt.scatter(x, y, ',', c = colors, cmap= 'magma', vmin = 0, vmax = 1000) 
plt.axis('equal') 
plt.axis([-2,1,-1.5,1.5]) 
plt.title('Mandelbrot Set', y = 1.05) 
plt.ylabel('Im') 
plt.xlabel('Re') 
plt.colorbar() 
plt.show() 

: 같은, 내 코드 보인다. 예를 들어, n이 1000이면 (최대 반복) 검은 색 점이 있고 다른 색이 n = 0 인 경우입니다.

+0

이 예제를 봐 http://matplotlib.org/devdocs//examples/showcase/mandelbrot.html – Serenity

답변

0

코드가 잘 작동한다고 생각합니다. 마커를 정의하면됩니다.

plt.scatter(x, y, marker=',', c = colors, cmap= 'magma', vmin = 0, vmax = 1000) 

enter image description here