散景线图未按预期工作

时间:2017-10-26 16:14:28

标签: python pandas bokeh

我试图使用散景绘制折线图,​​但得到奇怪的图表。我对散景库没有太多经验。我创建了ColumnDataSource并将其传递给了图。以下是我的源数据。

{'x': [datetime.date(2017, 8, 8),
  datetime.date(2017, 8, 9),
  datetime.date(2017, 8, 13),
  datetime.date(2017, 8, 14),
  datetime.date(2017, 8, 17),
  datetime.date(2017, 8, 18),
  datetime.date(2017, 8, 19),
  datetime.date(2017, 8, 22),
  datetime.date(2017, 8, 24),
  datetime.date(2017, 8, 26),
  datetime.date(2017, 8, 27),
  datetime.date(2017, 8, 28),
  datetime.date(2017, 8, 10),
  datetime.date(2017, 8, 11),
  datetime.date(2017, 8, 12),
  datetime.date(2017, 8, 16),
  datetime.date(2017, 8, 20),
  datetime.date(2017, 8, 21),
  datetime.date(2017, 8, 23),
  datetime.date(2017, 8, 29),
  datetime.date(2017, 8, 30),
  datetime.date(2017, 8, 31),
  datetime.date(2017, 9, 1),
  datetime.date(2017, 9, 2),
  datetime.date(2017, 9, 3),
  datetime.date(2017, 9, 4),
  datetime.date(2017, 9, 9),
  datetime.date(2017, 9, 5),
  datetime.date(2017, 9, 6),
  datetime.date(2017, 9, 7),
  datetime.date(2017, 9, 8),
  datetime.date(2017, 9, 10),
  datetime.date(2017, 9, 11),
  datetime.date(2017, 9, 12),
  datetime.date(2017, 9, 13),
  datetime.date(2017, 9, 14),
  datetime.date(2017, 9, 15),
  datetime.date(2017, 9, 16),
  datetime.date(2017, 9, 17),
  datetime.date(2017, 9, 19),
  datetime.date(2017, 9, 27),
  datetime.date(2017, 9, 20),
  datetime.date(2017, 9, 21),
  datetime.date(2017, 9, 22),
  datetime.date(2017, 9, 23),
  datetime.date(2017, 9, 24),
  datetime.date(2017, 9, 25),
  datetime.date(2017, 9, 26),
  datetime.date(2017, 9, 28)],
 'y': created_date_x
 2017-08-08     9.0
 2017-08-09    10.0
 2017-08-10     9.0
 2017-08-11     8.0
 2017-08-12     8.0
 2017-08-13     8.0
 2017-08-14     7.0
 2017-08-16     8.0
 2017-08-17     9.0
 2017-08-18     9.0
 2017-08-19     9.0
 2017-08-20     8.0
 2017-08-21     8.0
 2017-08-22     7.0
 2017-08-23    10.0
 2017-08-24    11.0
 2017-08-26     9.0
 2017-08-27     7.0
 2017-08-28     7.0
 2017-08-29     9.0
 2017-08-30     8.0
 2017-08-31     7.0
 2017-09-01     8.0
 2017-09-02     7.0
 2017-09-03     7.0
 2017-09-04     7.0
 2017-09-05     7.0
 2017-09-06     7.0
 2017-09-07     8.0
 2017-09-08     8.0
 2017-09-09     7.0
 2017-09-10     7.0
 2017-09-11     7.0
 2017-09-12     7.0
 2017-09-13     8.0
 2017-09-14     8.0
 2017-09-15     7.0
 2017-09-16     7.0
 2017-09-17     6.0
 2017-09-19     7.0
 2017-09-20     7.0
 2017-09-21     8.0
 2017-09-22     7.0
 2017-09-23     7.0
 2017-09-24     6.0
 2017-09-25     6.0
 2017-09-26     7.0
 2017-09-27     7.0
 2017-09-28     7.0
 Name: num_of_times_booked, dtype: float64}

以及绘制图表的代码如下。

po = figure(title='Portland booking data', y_axis_label='Num of time Booked', x_axis_label='Time', x_axis_type="datetime", plot_width=800)
po.line(x='x', y='y', source=source_2)
po.circle(x='x', y='y', source=source_2)
show(po)

当我运行上面的代码时,我得到下面的图表。 enter image description here

为什么线相互交叉。我犯了什么错误吗?

1 个答案:

答案 0 :(得分:3)

哎呀我的错误日期没有在源中排序