点重复时使用matlibplot.pyplot绘制散点图 [英] Drawing scatter graph using matlibplot.pyplot when points are duplicate

查看:177
本文介绍了点重复时使用matlibplot.pyplot绘制散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用matlibplot.pyplot生成散点图,很多点都是重复的.因此,当我简单地使用pyplot.scatter方法绘制图形时,许多点在一个点上被覆盖.为了考虑该位置上的点数,我认为我需要设置不同的点大小,如果该点包含更多数据点,则需要设置更大的圆圈.

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!

推荐答案

最简单的方法是设置一个较低的alpha,然后当这些点在彼此上方绘制时,它们看起来会更暗.

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()

当然,您也可以直接更改点的大小或颜色.为此,您需要找到重叠点的数量,然后设置大小(使用s散点图参数)或颜色(使用c)或同时设置两者. (但是设置Alpha是最简单的,因为它不需要显式地计算重叠.)

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.)

这篇关于点重复时使用matlibplot.pyplot绘制散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆