Drawing scatter graph using matlibplot.pyplot when points are duplicate

穿精又带淫゛_ 提交于 2019-12-11 12:47:19

问题


I want to generate a scatter graph using matlibplot.pyplot and a lot of points are duplicate. So when I simply draw a graph use pyplot.scatter method, many points are overdrawn on one dot. In order to consider the number of points on that position, I think I need to set a different point size, like a bigger circle if the spot contains more data points.

Can someone give me a pointer on how to do this? Thanks!


回答1:


The easiest way to do this is to set a low alpha, and then when the points plot on top of each other they look darker.

import numpy as np
import matplotlib.pyplot as plt

data = [i for i in range(8) for j in range(np.random.randint(10))]
x, y = np.array(data), np.array(data)
plt.scatter(x, y, alpha=.1, s=400)
plt.show()

Of course, you can also change the size of the point or the color directly. To do this, you need to find the number of overlapping points and then set the size (using the s scatter plot parameter) or the color (using c) or both. (But setting alpha is easiest since it doesn't require explicitly counting the overlaps.)



来源:https://stackoverflow.com/questions/21081453/drawing-scatter-graph-using-matlibplot-pyplot-when-points-are-duplicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!