在BokeH中绘制热图显示空图

问题描述 投票:0回答:1

我正在尝试在散景中绘制热图(频谱图),但是当热图显示为空时。。>

这是仅包含一些示例数据的代码,但是可以扩展为通过json获取大型数据集。

from math import pi
import pandas as pd

from bokeh.io import show
from bokeh.models import LinearColorMapper, BasicTicker, PrintfTickFormatter, ColorBar
from bokeh.plotting import figure

# initialise data of lists. 
data = {'epoch':[63745131000000, 63745131000000, 63745131100000,63745131100000], 'energy':[1.06811, 1.22078, 1.59495, 1.82245],'value':[3981.9308143034305, 2868.5202872178324, 1330.887696894385, 745.6847248644897]} 

# Creates pandas DataFrame. 
df = pd.DataFrame(data) 

# print the data 
print(df)

# this is the colormap from the original NYTimes plot
colors = ['#00007F', '#0000ff', '#007FFF', '#00ffff', '#7FFF7F', '#ffff00', '#FF7F00', '#ff0000', '#7F0000']
mapper = LinearColorMapper(palette=colors, low=df.value.min(), high=df.value.max())

TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"

epochs = list(df.epoch.drop_duplicates())
print(epochs)
energies = list(df.energy.drop_duplicates())
print(energies)


p = figure(title="My Plot", 
           x_axis_location="below", 
           tools=TOOLS, toolbar_location='below',
           tooltips=[('epoch', '@epoch'), ('energy', '@energy'), ('value', '@value')])

p.xaxis.ticker = epochs
p.yaxis.ticker = energies

p.grid.grid_line_color = None
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_text_font_size = "5pt"
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = pi / 3

p.rect(x="epoch", y="energy", width=1, height=1,
       source=df,
       fill_color={'field': 'value', 'transform': mapper},
       line_color=None)

color_bar = ColorBar(color_mapper=mapper, major_label_text_font_size="5pt",
                     ticker=BasicTicker(desired_num_ticks=len(colors)),
                     label_standoff=6, border_line_color=None, location=(0, 0))
p.add_layout(color_bar, 'right')

show(p)

输出的帧看起来正确:

            epoch   energy        value
0  63745131000000  1.06811  3981.930814
1  63745131000000  1.22078  2868.520287
2  63745131100000  1.59495  1330.887697
3  63745131100000  1.82245   745.684725

以及x和y的范围也看起来不错:

[63745131000000, 63745131100000]
[1.06811, 1.22078, 1.59495, 1.82245]

但是出现的图像没有绘制点:enter image description here

[我应该提一下,如果我只是简单地将第二个时期更改为一个,例如)

'epoch':[63745131000000, 63745131000000, 63745131000001,63745131000001]

然后图表似乎正确显示:

enter image description here

非常感谢您的帮助。谢谢

我试图在散景中绘制热图(频谱图),但是当热图显示为空时。这是仅包含一些示例数据的代码,但是它将扩展为获取大型数据集...

python pandas dataframe bokeh spectrogram
1个回答
0
投票

之所以没有显示任何信息,是因为在背景虚化处,您似乎不认为您的数据部分值得保留。

© www.soinside.com 2019 - 2024. All rights reserved.