是否有等效于bokeh的matplotlib outlinef?

时间:2019-01-11 06:54:31

标签: python matplotlib bokeh

我需要在bokeh中执行某些操作,这是我在matplotlib中成功完成的。

我使用matplotlib绘制轮廓图,并使用Contourf函数在侧面绘制颜色条。 我不使用网状网格功能,因为我已经分别具有(78,60001)形状数组中的X,Y和Z数据。 所以这是可行的:

array1[0].shape
(78, 60001)
array1[1].shape
(78, 60001)
array1[2].shape
(78, 60001)
CS = plt.contourf(array1[0], array1[1], array1[2], 25, cmap = plt.cm.jet)

哪个给出以下结果:

3d-fft

在bokeh中我该怎么做?互联网和手册上的大多数示例都使用Meshgrid。

===

更新#1: 例: https://bokeh.pydata.org/en/latest/docs/gallery/image.html

我尝试了以下bokeh代码,如下所示:

p.image(array1[2], array1[0], array1[1], dw=10, dh=10, palette="Spectral11")

哪个出现以下错误:

 RuntimeError: Columns need to be 1D (x is not)

===

更新#2:

p.image(array1[2].ravel(), array1[0].ravel(), array1[1].ravel(), dw=10, dh=None, palette="Spectral11")

上面的代码创建了HTML文件,但未显示任何图。

2 个答案:

答案 0 :(得分:1)

  

RuntimeError:列必须为一维(x不是)

这样做的原因是您试图传递图像的每个像素的坐标,但这不是Bokeh期望的。对于每个2D图像数据(RGBA数组或要在客户端中进行颜色映射的标量数据),Bokeh只希望为x,y,dw和dh中的每一个接收一个值。 x和y坐标是图像左下角的坐标。 dw和dh是数据空间坐标中图像的宽度和高度。

可以将多个图像传递给对image_rgbaimage的单个调用。在这种情况下,x,y,dw和dh对于每个图像都将具有单个值。即x是一维数字数组(每个图像一个)。

答案 1 :(得分:0)

我觉得hvplot library会回答你的问题。

请参阅上的Xarray dataset下面一个可再现的示例:

import xarray as xr
import hvplot.xarray  # noqa

import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

air_ds = xr.tutorial.open_dataset('air_temperature').load()
meanairbyyear = air_ds.air.groupby('time.year').mean()
stdairbyyear = air_ds.air.groupby('time.year').std()

meanair2d = xr.Dataset(
    {
        "y2013": (["lat", "lon"], meanairbyyear[0,:,:]),
        "y2014": (["lat", "lon"], meanairbyyear[1,:,:]),
    },
    coords={
        "lon": ("lon", meanairbyyear.lon),
        "lat": ("lat", meanairbyyear.lat),
    },
)

meanair2d

pl=meanair2d.hvplot.contourf(z='y2013',width=400)

from bokeh.models import HoverTool
MyHover = HoverTool(
    tooltips=[
        ( 'x', '$x'),
        ( 'y', '$y'),
        ( 'Year 2013', '@y2013{%3.0f} degC'),      
   ],
    formatters={
        '$x' : 'numeral',
        '$y' : 'numeral',
        '@y2013' : 'printf',      
    },
    point_policy="follow_mouse"
)

pl.opts(tools = [MyHover])

enter image description here

相关问题