将图外的点设置为上限 [英] Set points outside plot to upper limit

查看:65
本文介绍了将图外的点设置为上限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这个问题已经存在,但是我找不到.

Maybe this question exists already, but I could not find it.

我正在用Python绘制散点图.出于说明目的,我不想将轴范围设置为包括所有点-可能有一些非常高或非常低的值,而我所关心的只是这些点的存在-也就是说,它们需要在情节中,而不是其实际价值-而是位于画布顶部的某个位置.

I am making a scatter plot in Python. For illustrative purposes, I don't want to set my axes range such that all points are included - there may be some really high or really low values, and all I care about in those points is that they exist - that is, they need to be in the plot, but not on their actual value - rather, somewhere on the top of the canvas.

我知道在IDL中有一个很好的简短语法:在plot(x,y<value)中,y中任何大于value的值都将简单地放在y=value.

I know that in IDL there is a nice short syntax for this: in plot(x,y<value) any value in y greater than value will simply be put at y=value.

我正在寻找Python中类似的东西.有人可以帮我吗?

I am looking for something similar in Python. Can somebody help me out?

推荐答案

,您可以只使用

you can just use np.minimum on the y data to set anything above your upper limit to that limit. np.minimum calculates the minima element-wise, so only those values greater than ymax will be set to ymax.

例如:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0., np.pi*2, 30)
y = 10. * np.sin(x)

ymax = 5

fig, ax = plt.subplots(1)
ax.scatter(x, np.minimum(y, ymax))

plt.show()

这篇关于将图外的点设置为上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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