是否可以在不使用熊猫的情况下在散景图中创建xaxis?我可以导入Python datetime模块来创建xaxis吗?
在Bokeh文档中,他们显示了这一点:
import pandas as pd
from bokeh.plotting import figure, output_file, show
from bokeh.sampledata.stocks import AAPL
df = pd.DataFrame(AAPL)
df['date'] = pd.to_datetime(df['date'])
output_file("datetime.html")
# create a new plot with a datetime axis type
p = figure(plot_width=800, plot_height=250, x_axis_type="datetime")
p.line(df['date'], df['close'], color='navy', alpha=0.5)
show(p)
我正在尝试这样的事情:
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, DatetimeTickFormatter
from bokeh.plotting import figure
from datetime import datetime
p = figure(plot_height=400, plot_width=1200, x_axis_type="datetime")
p.xaxis.formatter = DatetimeTickFormatter(hours=["%H:%M:%S"],days=["%H:%M:%S"],months=["%H:%M:%S"],years=["%H:%M:%S"])
代码运行但我没有看到任何x或y轴。
不使用熊猫:
from bokeh.plotting import figure, output_file, show
from bokeh.models import DatetimeTickFormatter
from bokeh.sampledata.stocks import AAPL
import datetime
output_file("datetime.html")
AAPL['date'] = [datetime.datetime.strptime(x, "%Y-%m-%d").date() for x in AAPL['date']]
p = figure(plot_width=800, plot_height=250)
p.xaxis[0].formatter = DatetimeTickFormatter()
p.line(AAPL['date'], AAPL['close'], color='navy', alpha=0.5)
show(p)