基于数组和颜色映射来遮蔽matplotlib的背景 [英] Shade the background of matplotlib based on array and colormap
本文介绍了基于数组和颜色映射来遮蔽matplotlib的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为简单起见,假设我们有:
x = arange(1,5,0.01)
y = sin(x)
plot(x,y)
那么是否可以根据y值遮住轴的背景?
阴影可以通过将包含x和y的数组传递给imshow来实现,例如:
imshow(array,cmap ='hot')
这可能吗?
解决方案
确定可能:
x = arange(1,5,0.01)
yarr = vstack((x,))
y = sin(x)
imshow(yarr,extent = max(y)),cmap = cm.hot)
plot(x,y,color ='cornflowerblue',lw = 4)
extent关键字匹配图像的限制与绘制的数据。
这会给你:
I wonder if it is possible to shade the background of a typical matplotlib plot according to the data being plotted.
For simplicity, say we have:
x=arange(1,5,0.01) y=sin(x) plot(x,y)
Is it then possible to shade the background of the axes based on the y value?
The shading could be achieved by passing an array containing x and y to imshow such as:
imshow(array, cmap='hot')
although I want to have a line plot of x and y on top of this imshow figure.
Is this possible please?
解决方案Sure it's possible:
x = arange(1,5,0.01) yarr = vstack((x,)) y = sin(x) imshow(yarr, extent=(min(x),max(x), min(y),max(y)), cmap=cm.hot) plot(x, y, color='cornflowerblue',lw=4)
The extent keyword matches the limits of the image to the plotted data.
This will give you:
这篇关于基于数组和颜色映射来遮蔽matplotlib的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文