问题描述
由于某种原因,我无法在bokeh中绘制面积图.
I am unable to plot the area chart in bokeh for some reason..
下面是用于此操作的代码.
Below is the code used for the same..
from bokeh.charts import Area, show, output_file
Areadict = dict(
I = df['IEXT'],
Date=df['Month'],
O = df['OT']
)
area = Area(Areadict, x='Date', y=['I','O'], title="Area Chart",
legend="top_left",
xlabel='time', ylabel='memory')
output_file('area.html')
show(area)
我所能看到的都是是否绘制了日期轴,但没有看到我感兴趣的两个区域图的迹象.请指教
All i see if the date axis getting plotted, but no signs of the two areacharts that I am interested in.Please advise
推荐答案
我建议您查看 Holoviews 在Bokeh之上构建的非常高级的API,并得到Bokeh团队的认可.您可以在其文档中看到一个区域图示例一个>.基本上看起来像这样:
I would recommend looking at Holoviews which is a very high level API built on top of Bokeh, and is endorsed by the Bokeh team. You can see an Area chart example in their documentation. Basically it looks like:
# create holoviews objects
dims = dict(kdims='time', vdims='memory')
python = hv.Area(python_array, label='python', **dims)
pypy = hv.Area(pypy_array, label='pypy', **dims)
jython = hv.Area(jython_array, label='jython', **dims)
# plot
overlay.relabel("Area Chart") + hv.Area.stack(overlay).relabel("Stacked Area Chart")
会导致
否则,从Bokeh 0.13开始,使用稳定的bokeh.plotting
API创建堆积面积图,您将需要自己堆积数据,如此示例:
Otherwise, as of Bokeh 0.13 to create a stacked area chart with the stable bokeh.plotting
API, you will need to stack the data yourself, as shown in this example:
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show, output_file
from bokeh.palettes import brewer
N = 20
cats = 10
df = pd.DataFrame(np.random.randint(10, 100, size=(N, cats))).add_prefix('y')
def stacked(df):
df_top = df.cumsum(axis=1)
df_bottom = df_top.shift(axis=1).fillna({'y0': 0})[::-1]
df_stack = pd.concat([df_bottom, df_top], ignore_index=True)
return df_stack
areas = stacked(df)
colors = brewer['Spectral'][areas.shape[1]]
x2 = np.hstack((df.index[::-1], df.index))
p = figure(x_range=(0, N-1), y_range=(0, 800))
p.grid.minor_grid_line_color = '#eeeeee'
p.patches([x2] * areas.shape[1], [areas[c].values for c in areas],
color=colors, alpha=0.8, line_color=None)
show(p)
这将导致
这篇关于散景面积图无法绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!