主要信息来自官网

Getting Started — SchemDraw 0.14 documentation

1. 了解元器件

基本元件:阻容感,开关,插座,运放,电缆,变压器,基本够用了?

  • Basic Elements

    • Two-terminal
    • Single-Terminal
    • Switches
    • Audio Elements
    • Labels
    • Operational Amplifiers
    • Transistors
    • Cables
    • Transformers

库里的芯片: 逻辑芯片,数码管, DIP封装片,预定义芯片

  • Integrated Circuits

    • Multiplexers
    • Seven-Segment Display
    • DIP Integrated Circuits
    • Predefined ICs

连接器:单排,双排,跳线帽,DB头,数据总线,电源插座

  • Connectors

    • Headers
    • D-Sub Connectors
    • Multiple Lines
    • Data Busses
    • Outlets

组合原件:光耦,继电器,桥堆

  • Compound Elements

    • Optocoupler
    • Relay
    • Wheatstone
    • Rectifier

逻辑电路: 门电路,组合逻辑, 真值表,

  • Digital Logic

    • Logic Parser
    • Truth Tables
    • Karnaugh Maps

时序图: 信号时序

  • Timing Diagrams

    • Using JSON
    • Schemdraw’s Customizations

信号处理:可以认为来表示DSP的处理能力

流程图及框图:流程图,连接线,状态图,决策图,

  • Flowcharts and Diagrams

    • Connecting Lines
    • Decisions
    • Layout and Flow

电路库及其丰富,包括电路示意图等等

2. 基本操作

place 放置元件

with schemdraw.Drawing() as d:d += elm.Capacitor()d += elm.Resistor()d += elm.Diode()

输出:

方向选择, 放置时增加方向的methods就可以改变防止方向,并且直到下次改变

    d += elm.Capacitor()d += elm.Resistor().up()d += elm.Resistor()d += elm.Diode().right()

输出结果:

theta方法可以设置偏转角度并保持,注意这里角度是绝对值:

    d += elm.Capacitor()d += elm.Resistor().up()d += elm.Resistor()d += elm.Diode().right()d +=elm.Resistor().theta(45)d +=elm.Resistor()d +=elm.Resistor().theta(135)

3. 各种连接方式

按方向(up,down,lef,right),按起点终点(at, to), 按端口,按x,y(tox,toy), 封闭(endpoints)

多连接, dot, push,pop

指定位置:drop, hold, here

at方法指定器件起始端连接引脚

    d += (opamp := elm.Opamp())d += elm.Resistor().left().at(opamp.in2).label("R1")d += elm.Resistor().at(opamp.in1).label("R2")d += elm.Resistor().right().at(opamp.out).label("R3")

dot方法打连接点, length方法增加长度

    d += elm.Dot()d += elm.Resistor()d += elm.Dot()d += elm.Diode().length(6)d += elm.Dot()

to方法指定末端连接位置

    R = d.add(elm.Resistor())C = d.add(elm.Capacitor().up())Q = d.add(elm.Diode().to(R.start))

tox和toy方法用于划线到指定位置,其实是to x 和to y

        d += (C := elm.Capacitor())d += elm.Diode()d += elm.Line().down()d += elm.Line().tox(C.start) # line to the x value of start of Cd += elm.Resistor().up()

endpoints方法更直接,在两个指定端点之间放置元件

        d += (R := elm.Resistor())d += (Q := elm.Diode().down(6))d += elm.Line().tox(R.start)d += elm.Capacitor().toy(R.start)d += elm.SourceV().endpoints(Q.end, R.start)

控制翻转: flip 左右, reverse 上下

        d += (opamp := elm.Opamp())d += elm.Zener().left().label('Normal').at(opamp.in1)d += elm.Zener().left().flip().label('Flip').at(opamp.in2)

push和pop方法用于配置绘制方向,可在连接点用于多个方向连接时的绘制

        d += elm.Inductor()d += elm.Dot()d.push()  # Save this drawing position/direction for laterd += elm.Capacitor().down()  # Go off in another direction temporarilyd += elm.Ground(lead=False)d.pop()   # Return to the pushed position/directiond += elm.Diode()

drop & hold 保持不移动

        d += elm.Diode()  # Normal placement: drawing position moves to end of elementd += elm.Dot().color('red')d.here = (0, -1)d += elm.Diode().hold()  # Hold method prevents position from changingd += elm.Dot().color('blue')

一个元件的位置坐标值为1

疑问: 网格是怎么定义的?

3. 配置参数,设置label

表达方式:label支持utf-8格式的字符串, 支持LaTeX数学公式表达方式

数学表达式的具体表达,可参考如下连接

Writing mathematical expressions — Matplotlib 3.5.1 documentation

with schemdraw.Drawing() as d:d += elm.Resistor().label('1MΩ')d += elm.Capacitor().label('1μF')d += elm.Capacitor().label(r'$v = \frac{1}{C} \int i dt$')d += elm.Resistor().at((0, -2)).label('$R_0$')d += elm.Capacitor().label('$x^2$')

放置位置, loc:top, bottom,right, left

    d += elm.Resistor().label('1MΩ')d += elm.Capacitor().label('1μF')d += elm.Capacitor().label(r'$v = \frac{1}{C} \int i dt$')d += elm.Resistor().at((0, -2)).label('$R_0$')d += elm.Capacitor().label('$x^2$')# label for locationd += (elm.Resistor().at((0,-4)).label('Label')  # 'top' is default.label('Bottom', loc='bottom').label('Right', loc='right').label('Left', loc='left'))

放置位置也可以跟随角点走

    # label for valued += elm.Resistor().label('1MΩ')d += elm.Capacitor().label('1μF')d += elm.Capacitor().label(r'$v = \frac{1}{C} \int i dt$')d += elm.Resistor().at((0, -2)).label('$R_0$')d += elm.Capacitor().label('$x^2$')# label for locationd += (elm.Resistor().at((0,-4)).label('Label')  # 'top' is default.label('Bottom', loc='bottom').label('Right', loc='right').label('Left', loc='left'))d += (elm.BjtNpn().at((0,-6)).label('b', loc='base').label('c', loc='collector').label('e', loc='emitter'))

也可以控制label的走向,位移,字体,排版和颜色

    d += elm.Resistor().label('no offset').at((0,-10))d += elm.Resistor().label('offset', ofst=1)d += elm.Resistor().label('offset (x, y)', ofst=(-.6, .2))d += elm.Resistor().theta(-45).label('no rotate')d += elm.Resistor().theta(-45).label('rotate', rotate=True)d += elm.Resistor().theta(45).label('90°', rotate=90, color="red")

电压类的label, 可以用gap元素来作为截断点

   # label for gapd += elm.Line().dot(open=True)d += elm.Gap().label(('–','$V_o$','+'))d += elm.Line().idot(open=True)

电流箭头label ,加reverse()方法可以调转方向

# label for voltaged += elm.Resistor().label(('-','$R_1$','+')) # label for gapd += elm.Line().dot(open=True)d += elm.Gap().label(('–','$V_o$','+'))d += elm.Line().idot(open=True)R1 = d.add(elm.Resistor().down())d += elm.CurrentLabel().at(R1).label('10 mA').reverse()

线内的电流箭头:

# label for voltaged += elm.Resistor().label(('-','$R_1$','+')) # label for gapd += elm.Line().dot(open=True)d += elm.Gap().label(('–','$V_o$','+'))d += elm.Line().idot(open=True)R1 = d.add(elm.Resistor().down())d += elm.CurrentLabel().at(R1).label('10 mA').reverse()d+=elm.Line(3).left()R2 = d.add(elm.Resistor().left())d += elm.CurrentLabelInline(direction='in').at(R2).label('10 mA')

Loop Current 电流环

    # loop currentR1 = d.add(elm.Resistor().label("R1"))C1 = d.add(elm.Capacitor().label("C1").down())D1 = d.add(elm.Diode().label("D1",loc='bottom').fill(True).left())L1 = d.add(elm.Inductor().label("L1").up())d += elm.LoopCurrent([R1, C1, D1, L1], direction='cw').label('$I_1$')

非常贴心的功能,批注Annotations

# loop currentR1 = d.add(elm.Resistor().label("R1"))C1 = d.add(elm.Capacitor().label("C1").down())D1 = d.add(elm.Diode().label("D1",loc='bottom').fill(True).left())L1 = d.add(elm.Inductor().label("L1").up())d += elm.LoopCurrent([R1, C1, D1, L1], direction='cw').label('$I_1$')parallel = d.add(elm.Encircle([R1], padx=.8).linestyle('--').linewidth(1).color('red'))series = d.add(elm.Encircle([C1], padx=.8).linestyle('--').linewidth(1).color('blue'))d += elm.Annotate().at(parallel.NNE).delta(dx=1, dy=1).label('R1 annotation').color('red')d += elm.Annotate(th1=0).at(series.ENE).delta(dx=1.5, dy=1).label('D1 annotation').color('blue')

4. style 样式

元件样式包括: color, fill, linewidth ,linestyle ,未单独定义情况下,数值来自global defaults缺省值

with schemdraw.Drawing(color='blue', fill='lightgray') as d:# All elements are blue with lightgray fill unless specified otherwised += elm.Diode()d += elm.Diode().fill('red')        # Fill overrides drawing color hered += elm.Resistor().fill('purple')  # Fill has no effect on non-closed elementsd += elm.RBox().linestyle('--').color('orange')d += elm.Resistor().linewidth(5)

config方法可以定义全局样式

schemdraw.config(lw=1, font='serif')
with schemdraw.Drawing() as d:
    d += elm.Resistor().label('100KΩ')
    d += elm.Capacitor().down().label('0.1μF', loc='bottom')
    d += elm.Line().left()
    d += elm.Ground()
    d += elm.SourceV().up().label('10V')

设置风格(背景? )

Themes

Schemdraw also supports themeing, to enable dark mode, for example. The defined themes match those in the Jupyter Themes package:

  • default (black on white)

  • dark (white on black)

  • solarizedd

  • solarizedl

  • onedork

  • oceans16

  • monokai

  • gruvboxl

  • gruvboxd

  • grade3

  • chesterish

测试了几个样式 .....

onedork

solarizedd

monokai

5.  backend 相当于画布canvas

就是两样: matplotlib和SVG, 默认matplotlib, 配置成svg可以直接被网页引用,更方便,尤其是不需要单独调入字体。

选择依据,参见官方说明:

Reasons to choose the SVG backend include:

  • No Matplotlib/Numpy dependency required (huge file size savings if bundling an executable).

  • Speed. The SVG backend draws 4-10x faster than Matplotlib, depending on the circuit complexity.

Reasons to use Matplotlib backend:

  • To customize the schematic after drawing it by using other Matplotlib functionality.

  • To render directly in other, non-SVG, image formats, with no additional code.

5. 常用模块电路

  • Analog Circuits

    • Discharging capacitor
    • Capacitor Network
    • ECE201-Style Circuit
    • Loop Currents
    • AC Loop Analysis
    • Infinite Transmission Line
    • Power supply
  • Opamp Circuits
    • Inverting Opamp
    • Non-inverting Opamp
    • Multi-stage amplifier
    • Opamp pin labeling
    • Triaxial Cable Driver
  • Digital Logic
    • Half Adder
    • Full Adder
    • J-K Flip Flop
    • S-R Latch (Gates)
  • Timing Diagrams
    • SRAM read/write cycle
    • J-K Flip Flop
    • Tutorial Examples
  • Solid State
    • S-R Latch (Transistors)
    • 741 Opamp Internal Schematic
  • Integrated Circuits
    • 555 LED Blinker Circuit
    • Seven-Segment Display Counter
    • Arduino Board
    • 741 Opamp, DIP Layout
  • Signal Processing
    • Various Networks
    • Superheterodyne Receiver
    • Direct Conversion Receiver
    • Digital Filter
  • Flowcharting
    • It’s a Trap!
    • Flowchart for flowcharts
    • State Machine Acceptor
    • Door Controller
    • Another State Machine
    • Logical Flow Diagram
  • Styles
    • Resistor circle
    • Hand-drawn

6. 定制部件

Customizing Elements

  • Grouping Elements
  • Defining custom elements
    • Flux Capacitor Example
  • Segment objects
  • Matplotlib axis

群组复制

7. 输出SVG图片

加入backend定义:

with schemdraw.Drawing(backend="svg") as d:

然后用d.save(path)来保存svg图片

python实用库之schemdraw不只是绘制原理图相关推荐

  1. python 实用库

    最近学习时,遇到一些比较小但是很实用的第三方库. 1.colorclass 使用colorclass,可以使我们告别终端单调的色彩,让输出的内容更加多姿多彩,详细介绍请看 pypi地址 ,效果如下: ...

  2. 10个顶级Python实用库,推荐你试试!

    为什么我喜欢Python?对于初学者来说,这是一种简单易学的编程语言,另一个原因:大量开箱即用的第三方库,正是23万个由用户提供的软件包使得Python真正强大和流行. 在本文中,我挑选了15个最有用 ...

  3. python第三方库大概有多少人口_python绘制中国大陆人口热力图

    这篇文章给出了如何绘制中国人口密度图,但是运行存在一些问题,我在一些地方进行了修改. 本人使用的IDE是anaconda,因此事先在anaconda prompt 中安装Basemap包 conda ...

  4. python实用库_python常用库

    1,time 时间的表示形式: 格式化的字符串:'2018-2-4 14:08:01' 时间戳:1970年1月1日至今经历的秒数 元组(struct_time):time.struct_time(tm ...

  5. Python:第三篇【Python】实用库与框架-关东升-专题视频课程

    Python:第三篇[Python]实用库与框架-612人已学习 课程介绍         本课程包括6章.内容包括Python数据交换格式,Python数据库编程,Python网络编程,wxPyth ...

  6. Python培训教程分享:“高效实用” 的Python工具库

    作为一名合格Python技术员,对于Python工具库的使用是少不了的,本期Python培训教程就为大家分享的是""高效实用" 的Python工具库",希望能够 ...

  7. 离线安装python第三方库的实用方法:解决公司内网,服务器/电脑不能上网却需要安装python三方库问题(上:Windows环境中)

    离线安装python第三方库的实用方法:解决公司内网,服务器/电脑不能上网却需要安装python三方库问题(上:Windows环境中) 参考文章: (1)离线安装python第三方库的实用方法:解决公 ...

  8. 用Python turtle库绘制蟒蛇

    Python的函数库 Python语言与C语言Java类似,可以大量使用外部函数库包含在安装包中的函数库:. 比如math, random, turtle等其他函数库,其他函数库用户根据代码需求自行安 ...

  9. Python Tree库绘制多叉树的用法介绍

    Python Tree库绘制多叉树的用法介绍 Tree 库是一个 Python 的第三方库.这个库主要用于生成树和绘制树的图形. 一.安装Tree pip install Tree 使用 Tree 库 ...

  10. 用Python turtle库 绘制皮卡丘

    Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行 ...

最新文章

  1. Flutter 导包 以及体验
  2. sql sever avg保留小数_《数据库系统概念》笔记 (一)SQL
  3. java实现扫地agent_如何实现java agent?分享java agent的使用案例
  4. 用友3.0谋局“新两化” 融合创新迸发新动能
  5. Visual C++——Visual C++ 6.0 转 Visual Studio[Visual C++]编译错误[错误 D8016 “/ZI”和“/Gy-”命令行选项不兼容]解决方案
  6. 机器学习算法Python实现:word2vec 求词语相似度
  7. 简洁大气带进度条的URL跳转页面HTML源码
  8. 普林斯顿大学计算机系,普林斯顿大学计算机科学系
  9. 工大瑞普虚拟思科实验室full(U7.3)环境配置方法
  10. oracle 11g grid下载地址
  11. 傅里叶变换复数形式的实部代表什么_二维傅里叶变换与逆变换基于Unity的实现...
  12. UVA 10105 Polynomial Coefficients
  13. (73)Wangdao.com第十二天_JavaScript consol 对象与控制台
  14. 【redis】8数据结构(5种基本+3种特殊)
  15. c++ 编译error
  16. Future.get()抛出ExecutionException或InterruptedException?
  17. v-model的用法与解析
  18. VMware云管平台运维管理
  19. 新手小白怎么做shopee虾皮跨境?记住这三点不会被割“韭菜”
  20. 【数据分析】全球医疗卫生开放数据概览

热门文章

  1. 黎曼猜想到底是什么意思?
  2. [嵌入式学习]arm开发板通过NFS(网络文件系统)快捷访问和操作Ubuntu文件系统
  3. LOGO特训营 第六节 字体设计实操(矩形钢笔造字)
  4. Deep Gait Recognition: A Survey 阅读笔记
  5. 服务器阵列卡缓存显示错误,服务器阵列卡(缓存)
  6. echarts柱形图x轴y轴互换_echarts X Y轴互换后显示问题
  7. HDU1880——哈希表(BKDR算法)——魔咒词典
  8. Spark 名词解释
  9. 卡耐基梅陇大学计算机学院名人,卡内基梅隆大学_美国计算机专业排名前十
  10. SQL语句写起来太繁琐?你可以试试 MyBatis “动态” SQL