简体   繁体   English

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

[英]Plotting equations as lines in Bokeh - Python

I'm creating an XY chart in Bokeh with a 1:1 line and ideally two more lines for +/- 10% error and +/- 20% errors. 我正在Bokeh中创建一条1:1线的XY图表,理想情况下再创建两条线以实现+/- 10%的误差和+/- 20%的误差。 At the moment my chart works but seems unpythonic and shows too many legend entries. 目前,我的图表可以运行,但看起来有些不合常理,并且显示了太多图例条目。 The code at present: 目前的代码:

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)

So I'd like to replace the section where I'm defining q through u in order to plot two pairs of points for each error line with some equations that plot r/s (+/-10% error) and t/u (+/-20% error) for a qiven q instead. 因此,我想替换一下我通过u定义q的部分,以便使用一些绘制r / s(+/- 10%误差)和t / u(误差为+/- 20%)。 That way I'll end up with a single legend entry for each. 这样,我将为每个结局输入一个图例条目。

This throws an error though: 但这会引发错误:

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

And I'd still end up with duplicate entries for each error type 而且我仍然会为每种错误类型输入重复的条目

You can't multiply a list by a float. 您不能将列表乘以浮点数。 If I understand correctly, something like this should get the result you want: 如果我正确理解,类似这样的东西应该会得到想要的结果:

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

And replace the * 1.1 with 0.9, 1.2 and 0.8 for the other variations you wish to reference to q. 并将* 1.1与0.9、1.2和0.8替换为您希望引用q的其他变体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM