在Bokeh中将方程式绘制为线-Python

时间:2019-03-14 16:40:52

标签: python pandas numpy bokeh

我正在Bokeh中创建一条1:1线的XY图表,理想情况下再创建两条线以实现+/- 10%的误差和+/- 20%的误差。目前,我的图表可以运行,但看起来有些不合常理,并且显示了太多图例条目。 目前的代码:

import pandas as pd
from bokeh.plotting import figure, output_file, save
from bokeh.io import show, output_notebook
from bokeh.models import Span, HoverTool, ColumnDataSource
import numpy as np
# Call up duplicate plot

TOOLTIPS=[
    ("Sample", "@Sample"),
    ("Batch", "@Batch_No"),
    ("Source", "@Hole_ID"),
    ("Type", "@QC_Category")]

pdup = figure(title='Duplicate QC Review', x_axis_label='Duplicate', y_axis_label='Original', tools=tools_to_show, 
           tooltips=TOOLTIPS, outline_line_width=olwidth)

q = [0, 10000]
r = [0, 11000]
s = [0, 9000]
t = [0, 12000]
u = [0, 8000]

# 1:1 line, 10% and 20% error lines both above and below 1:1 line
pdup.line(q, q, color='green', legend='1:1')
pdup.line(q, r, color='orange', legend = '10%')
pdup.line(q, s, color='orange', legend = '-10%')
pdup.line(q, t, color='red', legend = '20%')
pdup.line(q, u, color='red', legend = '-20%')

pdup.circle(x='Copper_ppm', y='Cu_Duplicate', source=srcdup, size=10, color='green', legend='Copper (ppm)')
pdup.triangle(x='Gold_ppm', y='Au_Duplicate', source=srcdup, color='orange', size=10, legend='Gold (ppm)')
pdup.square(x='Molybdenum_ppm', y='Mo_Duplicate', source=srcdup, color='purple', size=10, legend='Molybdenum (ppm)')
pdup.diamond(x='Sulphur_ppm', y='S_Duplicate', source=srcdup, color='gray', size=10, legend='Sulphur (%)')

# Legend settings
# Make a series or connecting lines hidden by clicking on the legend entry
pdup.legend.click_policy='hide'
pdup.legend.border_line_color = "black"
pdup.legend.background_fill_color = "white"
pdup.legend.location = 'top_left'

show(pdup)

因此,我想替换通过u定义q的部分,以便使用一些绘制r / s(+/- 10%误差)和t的方程式为每条误差线绘制两对点/ u(误差为+/- 20%)来求第q个q。这样,我将为每个结局输入一个图例条目。

这会引发错误:

q = [0, 10000]
r = [q + (0.1 * q)]

对于每种错误类型,我仍然会得到重复的条目

1 个答案:

答案 0 :(得分:1)

您不能将列表乘以浮点数。如果我理解正确,那么类似的事情应该会得到想要的结果:

q = [0, 10000]
r = [q[0],q[1]*1.1]

对于要引用q的其他变体,将* 1.1替换为0.9、1.2和0.8。