Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.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
来自Python的交互式HTML绘图';从Bokeh到Latex_Python_Html_Matplotlib_Latex_Bokeh - Fatal编程技术网

来自Python的交互式HTML绘图';从Bokeh到Latex

来自Python的交互式HTML绘图';从Bokeh到Latex,python,html,matplotlib,latex,bokeh,Python,Html,Matplotlib,Latex,Bokeh,我想嵌入一个基于HTML的交互式绘图(例如,) 在我使用latex生成的pdf文档中。我可以使用pythontex在文档中嵌入基于matplotlib的绘图。但是,我无法嵌入如上所示的基于html的绘图 如果有任何见解,我将不胜感激。只要它们允许我嵌入交互式绘图,我愿意使用除latex(甚至Microsoft Word)以外的平台,Python笔记本除外。我把代码贴在下面。提前非常感谢您抽出时间 \documentclass[11pt]{article} \usepackage[utf8]{in

我想嵌入一个基于HTML的交互式绘图(例如,)
在我使用latex生成的pdf文档中。我可以使用pythontex在文档中嵌入基于matplotlib的绘图。但是,我无法嵌入如上所示的基于html的绘图

如果有任何见解,我将不胜感激。只要它们允许我嵌入交互式绘图,我愿意使用除latex(甚至Microsoft Word)以外的平台,Python笔记本除外。我把代码贴在下面。提前非常感谢您抽出时间

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}  
\usepackage{pythontex}
\usepackage{graphicx }

\begin{document}


\begin{pycode} 
from collections import OrderedDict
from math import log, sqrt

import numpy as np
import pandas as pd
from six.moves import cStringIO as StringIO

from bokeh.plotting import figure, show, output_file

antibiotics = """
bacteria,                        penicillin, streptomycin, neomycin, gram
Mycobacterium tuberculosis,      800,        5,            2,        negative
Salmonella schottmuelleri,       10,         0.8,          0.09,     negative
Proteus vulgaris,                3,          0.1,          0.1,      negative
Klebsiella pneumoniae,           850,        1.2,          1,        negative
Brucella abortus,                1,          2,            0.02,     negative
Pseudomonas aeruginosa,          850,        2,            0.4,      negative
Escherichia coli,                100,        0.4,          0.1,      negative
Salmonella (Eberthella) typhosa, 1,          0.4,          0.008,    negative
Aerobacter aerogenes,            870,        1,            1.6,      negative
Brucella antracis,               0.001,      0.01,         0.007,    positive
Streptococcus fecalis,           1,          1,            0.1,      positive
Staphylococcus aureus,           0.03,       0.03,         0.001,    positive
Staphylococcus albus,            0.007,      0.1,          0.001,    positive
Streptococcus hemolyticus,       0.001,      14,           10,       positive
Streptococcus viridans,          0.005,      10,           40,       positive
Diplococcus pneumoniae,          0.005,      11,           10,       positive
"""

drug_color = OrderedDict([
("Penicillin",   "#0d3362"),
("Streptomycin", "#c64737"),
("Neomycin",     "black"  ),
])

gram_color = {
    "positive" : "#aeaeb8",
    "negative" : "#e69584",
}

df = pd.read_csv(StringIO(antibiotics),
skiprows=1,
skipinitialspace=True,
engine='python')

width = 800
height = 800
inner_radius = 90
outer_radius = 300 - 10

minr = sqrt(log(.001 * 1E4))
maxr = sqrt(log(1000 * 1E4))
a = (outer_radius - inner_radius) / (minr - maxr)
b = inner_radius - a * maxr

def rad(mic):
return a * np.sqrt(np.log(mic * 1E4)) + b

big_angle = 2.0 * np.pi / (len(df) + 1)
small_angle = big_angle / 7

x = np.zeros(len(df))
y = np.zeros(len(df))

output_file("burtin.html", title="burtin.py example")

p = figure(plot_width=width, plot_height=height, title="",
x_axis_type=None, y_axis_type=None,
x_range=[-420, 420], y_range=[-420, 420],
min_border=0, outline_line_color="black",
background_fill="#f0e1d2", border_fill="#f0e1d2")

p.line(x+1, y+1, alpha=0)

# annular wedges
angles = np.pi/2 - big_angle/2 - df.index.to_series()*big_angle
colors = [gram_color[gram] for gram in df.gram]
p.annular_wedge(
x, y, inner_radius, outer_radius, -big_angle+angles, angles, color=colors,
)

# small wedges
p.annular_wedge(x, y, inner_radius, rad(df.penicillin),
-big_angle+angles+5*small_angle, -big_angle+angles+6*small_angle,
color=drug_color['Penicillin'])
p.annular_wedge(x, y, inner_radius, rad(df.streptomycin),
-big_angle+angles+3*small_angle, -big_angle+angles+4*small_angle,
color=drug_color['Streptomycin'])
p.annular_wedge(x, y, inner_radius, rad(df.neomycin),
-big_angle+angles+1*small_angle, -big_angle+angles+2*small_angle,
color=drug_color['Neomycin'])

# circular axes and lables
labels = np.power(10.0, np.arange(-3, 4))
radii = a * np.sqrt(np.log(labels * 1E4)) + b
p.circle(x, y, radius=radii, fill_color=None, line_color="white")
p.text(x[:-1], radii[:-1], [str(r) for r in labels[:-1]],
text_font_size="8pt", text_align="center", text_baseline="middle")

# radial axes
p.annular_wedge(x, y, inner_radius-10, outer_radius+10,
-big_angle+angles, -big_angle+angles, color="black")

# bacteria labels
xr = radii[0]*np.cos(np.array(-big_angle/2 + angles))
yr = radii[0]*np.sin(np.array(-big_angle/2 + angles))
label_angle=np.array(-big_angle/2+angles)
label_angle[label_angle < -np.pi/2] += np.pi # easier to read labels on the left side
p.text(xr, yr, df.bacteria, angle=label_angle,
text_font_size="9pt", text_align="center", text_baseline="middle")

# OK, these hand drawn legends are pretty clunky, will be improved in future release
p.circle([-40, -40], [-370, -390], color=list(gram_color.values()), radius=5)
p.text([-30, -30], [-370, -390], text=["Gram-" + gr for gr in gram_color.keys()],
text_font_size="7pt", text_align="left", text_baseline="middle")

p.rect([-40, -40, -40], [18, 0, -18], width=30, height=13,
color=list(drug_color.values()))
p.text([-15, -15, -15], [18, 0, -18], text=list(drug_color.keys()),
text_font_size="9pt", text_align="left", text_baseline="middle")

p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None

show(p) 

\end{pycode}

\begin{center} 
\includegraphics[width=1\textwidth]{burtin.html}
\end{center}

\end{document}
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pythontex}
\usepackage{graphicx}
\开始{document}
\开始{pycode}
从集合导入订单
从数学导入日志,sqrt
将numpy作为np导入
作为pd进口熊猫
从six.moves导入cStringIO作为StringIO
从bokeh.plotting导入图形,显示,输出文件
抗生素=”“”
细菌,青霉素,链霉素,新霉素,革兰氏
结核分枝杆菌,800,5,2,阴性
肖特米勒沙门菌,10,0.8,0.09,阴性
普通变形杆菌,3,0.1,0.1,阴性
肺炎克雷伯菌,850,1.2,1,阴性
流产布鲁氏菌,1,2,0.02,阴性
铜绿假单胞菌,850,2,0.4,阴性
大肠杆菌,100,0.4,0.1,阴性
伤寒沙门菌,1,0.4,0.008,阴性
产气杆菌,870,1,1.6,阴性
窦状布鲁氏菌,0.001,0.01,0.007,阳性
粪链球菌,1,1,0.1,阳性
金黄色葡萄球菌,0.03,0.03,0.001,阳性
白色葡萄球菌,0.007,0.1,0.001,阳性
溶血性链球菌,0.001,14,10,阳性
绿色链球菌,0.005,10,40,阳性
肺炎双球菌,0.005,11,10,阳性
"""
药物颜色=订购的药物([
(“盘尼西林”),
(链霉素),
(“新霉素”、“黑色”),
])
克色={
“阳性”:“AEB8”,
“否定”:“e69584”,
}
df=pd.read_csv(抗生素),
skiprows=1,
skipinitialspace=True,
引擎(python)
宽度=800
高度=800
内半径=90
外半径=300-10
minr=sqrt(日志(.001*1E4))
maxr=sqrt(对数(1000*1E4))
a=(外半径-内半径)/(最小-最大)
b=内半径-a*maxr
def rad(话筒):
返回a*np.sqrt(np.log(mic*1E4))+b
大角度=2.0*np.pi/(len(df)+1)
小角度=大角度/7
x=np.零(len(df))
y=np.零(len(df))
输出文件(“burtin.html”,title=“burtin.py示例”)
p=图形(绘图宽度=宽度,绘图高度=高度,标题=”,
x_轴类型=无,y_轴类型=无,
x_范围=[-420420],y_范围=[-420420],
最小边框=0,轮廓线颜色=“黑色”,
背景填充=“#f0e1d2”,边框填充=“#f0e1d2”)
p、 直线(x+1,y+1,alpha=0)
#环形楔
角度=np.pi/2-大角度/2-测向索引到系列()*大角度
颜色=[gram_color[gram]表示df.gram中的gram]
p、 环形楔(
x、 y,内半径,外半径,-大角度+角度,角度,颜色=颜色,
)
#小楔子
p、 环形楔形物(x,y,内径,弧度(青霉素),
-大角度+角度+5*小角度,-大角度+角度+6*小角度,
颜色=药物颜色[青霉素])
p、 环形楔(x,y,内半径,rad(df.链霉素),
-大角度+角度+3*小角度,-大角度+角度+4*小角度,
颜色=药物颜色[链霉素])
p、 环形楔形物(x,y,内半径,rad(df.新霉素),
-大角度+角度+1*小角度,-大角度+角度+2*小角度,
颜色=药物颜色[新霉素])
#圆轴和标签
标签=净功率(10.0,净功率(-3,4))
半径=a*np.sqrt(np.log(标签*1E4))+b
p、 圆(x,y,半径=半径,填充颜色=无,线条颜色=白色)
p、 文本(x[:-1],半径[:-1],[str(r)表示标签[:-1]中的r],
text\u font\u size=“8pt”,text\u align=“center”,text\u baseline=“middle”)
#径向轴
p、 环形楔块(x,y,内半径-10,外半径+10,
-大角度+角度,-大角度+角度,颜色=“黑色”)
#细菌标签
xr=半径[0]*np.cos(np.array(-big_angle/2+angles))
yr=半径[0]*np.sin(np.array(-big_角度/2+角度))
标签角度=np.数组(-大角度/2+角度)
label_angle[label_angle<-np.pi/2]+=np.pi#左侧标签更容易阅读
p、 文本(xr,yr,df.bacteries,角度=标签角度,
text\u font\u size=“9pt”,text\u align=“center”,text\u baseline=“middle”)
#好的,这些手绘的图例非常笨重,将在未来的版本中改进
p、 圆([-40,-40],-370,-390],颜色=列表(gram_color.values()),半径=5)
p、 text([-30,-30]、-370,-390],text=[“Gram-”+gr表示Gram_color.keys()中的gr,
text\u font\u size=“7pt”,text\u align=“left”,text\u baseline=“middle”)
p、 矩形([-40,-40,-40],[18,0,-18],宽度=30,高度=13,
颜色=列表(drug\u color.values())
p、 text([-15,-15,-15],[18,0,-18],text=list(drug_color.keys()),
text\u font\u size=“9pt”,text\u align=“left”,text\u baseline=“middle”)
p、 xgrid.grid\u line\u color=无
p、 ygrid.grid\u line\u color=无
表演(p)
\结束{pycode}
\开始{center}
\includegraphics[width=1\textwidth]{burtin.html}
\结束{中心}
\结束{document}

从Bokeh
0.12.1开始这是不可能的。尽管Bokeh是一个“Python”库,但它的设计和构思是为了简化浏览器中的交互式可视化。因此,它有一个大型JavaScript组件(实际上所有的工作都在这个组件中完成),并且需要一个运行的JavaScript引擎(即web浏览器)才能正常工作

有一个“保存工具”,可以让您通过手动单击