首页 > 其他分享 >使用Jupyter Notebook+bokeh绘图入门完整步骤

使用Jupyter Notebook+bokeh绘图入门完整步骤

时间:2023-06-09 20:08:12浏览次数:42  
标签:Jupyter randrange figure show label bokeh Notebook import axis


Bokeh是一款基于浏览器的交互式绘图工具,在IPython Notebook中具有非常好的表现。

安装anaconda3,单击开始菜单,单击下图红色箭头所指菜单启动Jupyter Notebook:

使用Jupyter Notebook+bokeh绘图入门完整步骤_go

然后在浏览器中单击下图中红色箭头指向的菜单:

使用Jupyter Notebook+bokeh绘图入门完整步骤_数据可视化_02

然后在单元格内编写下面的代码:

from bokeh.plotting import figure, output_file, show
from random import randrange# 生成测试数据
x = list(range(1,21))
y = [randrange(1,10) for _ in range(20)]
output_file('lines.html', title='lines')
p = figure(title='lines', x_axis_label='x', y_axis_label='y')# 设置图例
p.line(x, y, legend='lines', line_width=2)
show(p)

代码截图为:

使用Jupyter Notebook+bokeh绘图入门完整步骤_go_03

单击上图中红色箭头所指,运行代码,生成的图片如下图所示,注意红色方框内有一些工具可以对图片进行缩放、平移或保存。

使用Jupyter Notebook+bokeh绘图入门完整步骤_python_04

把代码改为:

from bokeh.plotting import figure, output_file, show
from random import randrange
x = list(range(1,21))
y = [randrange(1,10) for _ in range(20)]output_file('triangle.html', title='triangle')
p = figure(title='triangle', x_axis_label='x', y_axis_label='y')
p.triangle(x, y, legend='triangle', line_width=2)
show(p)

重新运行代码,得到的图像为:

使用Jupyter Notebook+bokeh绘图入门完整步骤_go_05

把代码改为:

from bokeh.plotting import figure, output_file, show
from random import randrange
x = list(range(1,21))
y = [randrange(1,10) for _ in range(20)]output_file('circle.html', title='circle')
p = figure(title='circle', x_axis_label='x', y_axis_label='y')
p.circle(x, y, legend='circle', line_width=2)
show(p)

重新运行代码,得到的图形为:

使用Jupyter Notebook+bokeh绘图入门完整步骤_go_06

标签:Jupyter,randrange,figure,show,label,bokeh,Notebook,import,axis
From: https://blog.51cto.com/u_9653244/6450946

相关文章

  • 关于Jupyter notebook无法自动跳转浏览器
    这个问题网上已经有一堆回答了,如:解决Jupyter-notebook不自动跳转浏览器的详细方法Python基础090:解决jupyternotebook无法自动跳转chrome浏览器的问题我这里的情况是针对浏览器路径设置的问题,这是你尝试解决之后还是打不开的主要原因。首先,一定要进入浏览器属性,进行目标位置查......
  • JupyterLab 4.0 发布了
    JupyterLab是JupyterNotebook的下一代版本,它提供了更强大的功能和更灵活的用户界面,6月6日,官方发布了JupyterLab4.0的说明,并且说该版本是下一个主要的版本。JupyterLab的主要改进是:用户界面:JupyterNotebook使用单个文档界面,以逐个标签的方式显示打开的笔记本。每个标签......
  • kaggle notebook 处理临时脚本的方法
    #=写入项目临时代码aaa='''#!/usr/bin/envpython#coding=utf-8#Copyright2023TheHuggingFaceInc.team.Allrightsreserved.##LicensedundertheApacheLicense,Version2.0(the"License");#youmaynotusethisfileexceptincom......
  • 【博学谷学习记录】超强总结,用心分享 | jupyter常用功能
    jupyter安装文档地址https://jupyter.org/installpipinstallnotebook启动命令jupyternotebookjupyter-themes修改主题安装主题https://github.com/dunovank/jupyter-themesgithub地址pipinstall--upgradejupyterthemes查看所有主题jt-l修改主题jt-tg......
  • MacBook 配置远程 jupyter lab
    在从事数据分析/处理过程中,JupyterLab是一个常见且便捷的工具,它属于JupyterNotebook的升级版本。除了可以在本机搭建Jupyter环境,它还支持通过网络远程访问,从而实现在本地编写查看代码,在远程服务器上运行代码的功能。需求背景我日常使用的是一台M1版本的MacBookAir,它......
  • 如何修改notebook内核对应的python地址
    要修改JupyterNotebook内核对应的Python地址,可以按照以下步骤进行:打开终端或命令提示符。列出当前可用的JupyterNotebook内核。运行以下命令:jupyterkernelspeclist,这将列出已安装的内核及其位置。找到您想要修改的内核对应的配置文件。在上一步的输出中,找到......
  • jupyter 报错 500 : internal server error
    之前代码搬迁服务器出了如下问题:jupyter报错500:internalservererror老服务器charset-normalizer的版本是3.0.1,但是看知乎有个方法如下:pipinstall--force-reinstallcharset-normalizer==3.1.0也可以解决问题,就没重装3.0.1......
  • the way to make jupyter output cell has a dark background in vscode
    theissuetobefixedAsshowninthepicture,jupyteroutputcellhasabrightbackground,evenit'sasktousedarkbackground.thewaytogoimportmatplotlib.pyplotaspltimportnumpyasnpfromIPython.displayimportHTML####################......
  • abc273_e Notebook 题解
    Notebook题意有\(q\)次操作。现在你有一个空序列\(a\)和一本\(10^9\)页的笔记本,每页纸上都有一个空序列。每次操作是以下四种中的一种:ADDx,表示在\(a\)的末尾插入一个整数\(x\)。DELETE,表示删除\(a\)的末尾的一个数,如果\(a\)序列为空则什么也不干。SAVEy,表......
  • Jupyter Notebook 10个提升体验的高级技巧
    Jupyter笔记本是数据科学家和分析师用于交互式计算、数据可视化和协作的工具。Jupyter笔记本的基本功能大家都已经很熟悉了,但还有一些鲜为人知的技巧可以大大提高生产力和效率。在这篇文章中,我将介绍10个可以提升体验的高级技巧。完整文章:https://avoid.overfit.cn/post/519c......