如何使用Matplotlib在点云中突出显示一个点? [英] How can I highlight a dot in a cloud of dots with Matplotlib?

查看:131
本文介绍了如何使用Matplotlib在点云中突出显示一个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matplotlib,我的目标是突出显示散点图中的一些要点.

I'm using Matplotlib and my goal is highlighting some points in a scatterplot.

我使用了以下代码:

$colors = {'true':'red', 'false':'blue'}

plt.scatter(data[T[j]], data[T[i]], c=data['upgrade'].apply(lambda x: colors[x]) $

如果条件为"true",此代码使我的点为红色,否则为蓝色.在有以下示例之前,我没有任何问题:

This code let my dots being red if the condition is "true", else blue. I haven't any problem until I had the following example:

2万个点,只有1为真.我获得的图无法显示我的唯一点,因为我有一团充满蓝色点(2k)的云,只有一个应该是红色的.

20k dots and just 1 is TRUE. The plot that I obtained can't display my only point, because I have a cloud full of blue dots (2k) and just one should be red.

我的问题是,通常是否可以通过某种方式显示我唯一的红点,以使红点比蓝色更突出.

My question is if there is some way to show my only red dots, in general, to let red dots being more highlighted than the blue.

谢谢.

推荐答案

您可以利用numpy具有数组条件的索引数组.然后有效地调用 scatter 两次.您最想打到顶部的那一个.

You can take advantage of numpy's indexing arrays with array conditions. And then efficiently call scatter twice. The ones you want on top you call last.

其他技巧包括使用不太强烈的蓝色,并使用点的大小.(请注意,点的大小是相对于其面积的,而不是其直径.)

Additional tricks include using a less intense blue, and playing with the size of the dots. (Note that the dot size is relative to its area, not its diameter.)

import numpy as np
import matplotlib.pyplot as plt

N = 2000
x = np.random.rand(N)
y = np.random.rand(N)
z = np.random.rand(N)
c = np.where(z < 0.001, 1, 0)
plt.scatter(x[c==0], y[c==0], c='#2c7bb6', s=10)
plt.scatter(x[c==1], y[c==1], c='#ff0000', s=80)
plt.show()

这篇关于如何使用Matplotlib在点云中突出显示一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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