如何更改散点图中的颜色密度?

时间:2020-06-25 05:58:10

标签: python python-3.x matplotlib plot scatter-plot

我有一个优化器,它获得2-d初始点,并产生一个2-d的答案。以下是其中红点是初始点而蓝点是解的图。

enter image description here

当我在循环中进行如下操作时,我看不到解点的密度。

import matplotlib.pyplot as plt
exp = 100
for i in range(exp):
  fx = convex()
  #plotting initial points
  plt.scatter(fx.x[0],fx.x[1], c='r',s=1)

  #Finding optimal solution 
  while fx.fvalue() > 1e-4:
    fx.new_x(l2=True, alpha = 6, sgd = True)
  #plotting optimal solution
  plt.scatter(fx.x[0],fx.x[1], c='b', s=1)
  plt.xlabel('x')
  plt.ylabel('y')
  plt.legend(['Initial values', 'Solutions'])

fxconvex类的实例,该类具有x作为其属性并被随机初始化,然后在while循环中进行更新。

我希望动态地或至少在结束for循环之后才能看到解点的累积。

0 个答案:

没有答案