Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Bokeh-Python将方程绘制为直线_Python_Pandas_Numpy_Bokeh - Fatal编程技术网

用Bokeh-Python将方程绘制为直线

用Bokeh-Python将方程绘制为直线,python,pandas,numpy,bokeh,Python,Pandas,Numpy,Bokeh,我正在Bokeh创建一个XY图表,其中有一条1:1的线,理想情况下还有两条线,误差为+/-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,

我正在Bokeh创建一个XY图表,其中有一条1:1的线,理想情况下还有两条线,误差为+/-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)
因此,我想替换我定义q到u的部分,用一些方程来绘制每条误差线的两对点,这些方程绘制q的r/s(+/-10%误差)和t/u(+/-20%误差)。这样的话,我会为每一个都添加一个图例条目

但这会引发一个错误:

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

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

你不能用浮点数乘以列表。如果我理解正确,像这样的事情应该会得到你想要的结果:

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

并将*1.1替换为0.9、1.2和0.8,用于您希望参考q的其他变体。

这很有效。然后,我只是让图例条目保持不变,它们按照需要出现在图例中。谢谢