You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Typst的CeTZ plot中设置绘图线条粗细?

CeTZ绘图:线条粗细设置与type参数说明

线条粗细调整

你当前代码中通过style: (paint: red, thickness: 50pt)设置线条粗细的语法是正确的,但50pt的宽度过于夸张,会导致图形严重变形,建议调整为更合理的数值(比如1pt~3pt)。

type参数的用法

type是plot.add的一级参数(与domain、samples同级),用于指定绘图的类型,可选值及效果如下:

  • "line":默认值,绘制连续线条
  • "points":绘制散点图
  • "area":填充曲线与坐标轴之间的区域
  • "step":绘制阶梯状线条
  • "stem":绘制茎状垂直线(从坐标轴到曲线点)

修改后的示例代码

#set page(height: auto)

#import "@preview/cetz:0.2.2"

#set align(center)
#cetz.canvas({
  import cetz.plot
  plot.plot(
    size: (14, 4), 
    axis-style: "school-book",
    x-tick-step: none, 
    y-tick-step: none, 
    x-minor-step: 0.00001,
    x-break: true,
    {
      // 自定义线条粗细的线条图
      plot.add(
        domain: (-10, 10), 
        samples: 1000,
        type: "line", // 显式指定线条类型(默认可省略)
        style: (paint: red, thickness: 2pt), // 合理的线条粗细
        x => if x < -1 {0} else if x>= -1 and x<=1 {(x+1) / 2} else {1}
      )
      // 填充区域类型示例
      plot.add(
        domain: (-10, 10), 
        samples: 1000,
        type: "area", // 指定为填充区域
        style: (paint: blue, opacity: 0.3), // 填充样式
        x => if x < -1 {1} else if x>= -1 and x<=1 {1 - (x+1) / 2} else {0}
      )
    }
  )
})
#set align(left)

关键说明

  • thickness属于style配置对象的属性,仅对线条类绘图("line"、"step"等)生效;
  • 不同type对应的style属性略有差异,比如"area"类型可以用opacity调整填充透明度,"points"可以用size调整点的大小。

内容的提问来源于stack exchange,提问作者Makogan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 00:43:12