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

2024-06-16 10:48:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个优化器获取二维初始点,并生成一个二维的答案。下图中红点为初始点,蓝点为解决方案

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循环之后看到解决方案点的累积


Tags: 答案trueforpltoptimalplotting解决方案密度