Density plot of chaos game using Python matplotlib? -


essentially i'm trying produce set of points via ifs , use color map show multiplicity of each point. in other words, if assume color map high values more yellow , lower ones more red, values repeatedly produced ifs more yellow.

i'm struggling correct results this. each thing i've tried has resulted in image looks interesting, incorrect differs wildly plotting points without color mapping.

below base code i'm comfortable with, without failed attempts @ color mapping. can proper color map?

the basic strategy, think, make matrix 'mat' holding point multiplicities , plt.imshow(xs, ys, c=mat. cmap="..."). i've tried different approaches keep coming incorrect results.

import numpy np import matplotlib.pyplot plt import random  def f(x, y, n):     n = np.array([[x, y]])      m = np.array([[1, 0], [0, 1]])      b = np.array([[.5], [0]])     b2 = np.array([[0], [.5]])      if n == 0:         return np.dot(m, n.t)      elif n == 1:        return np.dot(m, n.t) + b      elif n == 2:         return np.dot(m, n.t) + b2      elif n == 3:         return np.dot(m, n.t) - b      elif n == 4:         return np.dot(m, n.t) - b2   xs = [] # x coordinates ys = [] # y coordinates d = {}  # point multiplicities   random.seed()  x = 1 y = 1  in range(0, 100000):     n = random.randint(1, 4)      v = f(x, y, n)      x = v.item(0)     y = v.item(1)      xs.append(x)     ys.append(y)      xi = round(x, 3)     yi = round(y, 3)      if (xi, yi) in d:         d[(xi, yi)] += 1     else:            d[(xi, yi)] = 1  plt.xlabel('x') plt.ylabel('y')  plt.scatter(xs,ys, s=.05) plt.autoscale(true, true, true) plt.show() 

if understand problem, sounds want use 2d histogram density of points,

h, x, y = np.histogram2d(xs,ys,bins=100) x, y = np.meshgrid(x[:-1],y[:-1],indexing='ij') plt.pcolormesh(x,y,h,alpha=0.8, cmap = plt.cm.ylorrd_r) plt.colorbar() 

which gives,

enter image description here

this transparent colormesh plotted on scatter plot. colour scatter plot value @ point,

pc = some_fn_to_get_color_at_points(x, y, h, xs, yx) plt.scatter(xs,ys, s=.05, c=pc) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -