当前位置: 首页 > news >正文

在jupyter notebook中使用海龟绘图

首先,安装ipyturtle3 ref:ipyturtle3 · PyPI

pip install ipyturtle3

然后,安装ipycanvas

ipycanvas是一个需要安装在与JupyterLab实例相同环境的包。此外,您需要安装nodejs,并启用JupyterLab ipycanvas小部件。

所有这些都在ipycanvas安装说明中有详细介绍:

使用conda

conda install -c conda-forge ipycanvas

JupyterLab扩展

如果您已经安装了JupyterLab,还需要安装JupyterLab扩展。为了安装JupyterLab扩展,您需要先安装npm。您可以使用conda轻松安装npm:

conda install -c conda-forge nodejs

然后您可以安装JupyterLab扩展:

jupyter labextension install @jupyter-widgets/jupyterlab-manager ipycanvas

由于您提到您正在使用jupyterhub,如果您在集群上并且不是管理员,可能没有权限执行这些操作。如果是这种情况,请联系您的集群管理员,他们可能不允许用户启用扩展。

可以采用如下的代码测试是否安装成功

import ipyturtle3 as turtle
from ipyturtle3 import hold_canvas
myCanvas=turtle.Canvas(width=500,height=250)
display(myCanvas)
myTS=turtle.TurtleScreen(myCanvas)
myTS.clear()
myTS.bgcolor("lightgreen")
bob=turtle.Turtle(myTS)
jess=turtle.Turtle(myTS,isHolonomic=True)
jess.shape("square")
bob.shape("turtle")myTS.delay(200)
# Usual turtle Non-holonomic example
bob.forward(50)
bob.left(90)
bob.forward(50)
bob.left(90)
bob.forward(50)
bob.left(90)
bob.forward(50)#Holonomic
jess.moveleft(200)
jess.moveup(100)
jess.moveright(100)
jess.movedown(100)
jess.turnright(45)
jess.turn(-45)
jess.distance_at_angle(50,45)myTS.clear()# Rainbow benzene
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
t = turtle.Turtle(myTS)
myTS.bgcolor('black')
for x in range(50):with(hold_canvas(myCanvas)):t.pencolor(colors[x%6])t.width(x//100 + 1)t.forward(x)t.left(59)

在这里插入图片描述
ref:https://stackoverflow.com/questions/72410176/how-to-display-canvas-with-ipycanvas-on-jupyterhub

http://www.lryc.cn/news/133695.html

相关文章:

  • 密码学学习笔记(十八):Diffie–Hellman (DH) 密钥交换
  • Linux —— 进程间通信(管道)
  • python常用
  • jeecg如何创建报表并配置到菜单中
  • Servlet+JDBC实战开发书店项目讲解第12讲:会员管理功能
  • java面向对象——继承以及super关键字
  • [机缘参悟-101] :IT人 - 遵从世界本源的样子,不带个人情感、道德、认知倾向,接纳一切,你就拥有无限的力量
  • C++--深度理解智能指针
  • Spring Boot使用MySQL的默认连接池
  • conda使用教程
  • 什么是LLM大语言模型?
  • jenkins同一jar包部署到多台服务器
  • (四)Doceke安装MySQL镜像+Docker启动MySQL容器
  • Android Studio:Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
  • Spring Clould 搜索技术 - elasticsearch
  • android核绑定cpuset配置与检测进程所在核cpuset方法
  • Lnton羚通关于如何使用nanoPC-T4 安装OpenCV?
  • 内存泄漏:前端开发者的噩梦——内存泄露的原因及排查
  • 高效使用ChatGPT之ChatGPT客户端
  • 【腾讯云 TDSQL-C Serverless 产品体验】基于TDSQL-C 存储爬取的QQ音乐歌单数据
  • leetcode 6450. k-avoiding 数组的最小总和
  • 变压器绝缘油耐压试验
  • Windows控制台API官方文档
  • PyTorch DataLoader 报错 “DataLoader worker exited unexpectedly“ 的解决方案
  • 【AI绘画--七夕篇】:七夕特别教程,使用SDXL绘制你的心上人(Stable Diffusion)(封神榜—妲己)
  • hadoop2的集群数据将副本存储在hadoop3
  • c# ??=
  • 存储系统性能优化中IOMMU的作用是什么?
  • localhost:8080 is already in use
  • 机器学习深度学习——NLP实战(自然语言推断——数据集)