matplotlib:防止一些非常大(或很小)的值影响我的轮廓 [英] matplotlib: preventing a few very large (or small) values to affect my contour

查看:183
本文介绍了matplotlib:防止一些非常大(或很小)的值影响我的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些时候绘制数据时,会有一些非常大(或非常小的)数字,如果不注意这些数字,将会以不利的方式影响轮廓.一种解决方案是从轮廓颜色分级中取出最高和最低的10%数据,并将其视为小于和大于.下图显示了这个想法:

in plotting the data some times there are a few very large (or very small) numbers which, if not taken care of, will affect the contour in a bad way. a solution is to take out the 10% highest and lowest data out of the contour color grading and considering them as less than and more than. the following figure shows the idea:

条顶部和底部的两个箭头形状支持此想法.大于14的任何值将以白色显示,小于-2的任何值将以黑色显示.在matplotlib中怎么可能? 我该如何定义: -在条形两端的三角形部分中显示的两个类别中分别放入最高值的5%和最低值的5%? (我应该定义轮廓操作还是其他方法?) -如果我要提供某些值而不是百分比怎么办?例如,要求在白色三角形上放置大于14的值,而在黑色区域上放置小于-2的值?

the two arrow shapes on the top and the bottom of the bar support this idea. any value above 14 will be shown in white and any value below -2 will be shown in black color. how is it possible in matplotlib? How can I define: - to put the 5% of highest values and 5% of lowest values in two categories shown in the triangular parts in both ends of the bar? (Should I define it the contour operation or are there other ways?) - what if I want to give certain values instead of the percentage? for instance, ask to put any value above 14 on the white triangule and any value below -2 as black areas?

非常感谢您的帮助.

推荐答案

来自 http://matplotlib.org/examples/api/colorbar_only.html .您可以使用它,然后看看它是否可以解决您的问题.

Taken from http://matplotlib.org/examples/api/colorbar_only.html. You can play with it and you will see if it could solve your problem.

import matplotlib.pyplot as plt
from matplotlib import mpl
import numpy as np

x = np.linspace(-1,1,100)
X,Y = np.meshgrid(x,x)
Z = np.exp(-X**2-Y**2)

vmin = 0.3 #Lower value
vmax = 0.9 #Upper value

bounds = np.linspace(vmin,vmax,4)

cmap = mpl.colors.ListedColormap([(0,0,0),(0.5,0.5,0.5),(0,1,0),(1,1,1)])
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

plt.imshow(Z,cmap=cmap,interpolation='nearest',vmin=vmin,vmax=vmax)

ax = plt.colorbar().ax
cb = mpl.colorbar.ColorbarBase(ax, norm=norm,
                               extend='both',
                               cmap=cmap)
cmap.set_over([0,0,1])
cmap.set_under([1,0,0])

plt.show()

这篇关于matplotlib:防止一些非常大(或很小)的值影响我的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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