cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
819 stars 35 forks source link

Add legends to cetz.plot #354

Closed Kreijstal closed 9 months ago

Kreijstal commented 9 months ago

Just like matplotlib! Teachers will give you negative points if your plots don't have legends.

johannes-wolf commented 9 months ago

It's already on 0.2.0.

#cetz.canvas({
  import cetz.draw: *

  plot.plot(size: (8,6), {
    plot.add(domain: (0, 2*calc.pi), calc.sin, label: $ sin x $)
    plot.add(domain: (0, 2*calc.pi), calc.cos, label: $ cos x $)
  })
})

grafik

Kreijstal commented 9 months ago

I guess I'll have to wait till next release in https://github.com/typst/packages/

dscso commented 9 months ago

I tried this code in 2.0 unfortunately the grid is broken on the x side. Maybe this comment helps as a bug report

canvas({
    import draw: *

    plot.plot(
        size: (8,6),
        x-grid: true,
        y-grid: true,
        {
            plot.add(domain: (0, 2*calc.pi), calc.sin, label: $ sin x $)
            plot.add(domain: (0, 2*calc.pi), calc.cos, label: $ cos x $)
        }
    )
})
image
johannes-wolf commented 9 months ago

That also got fixed but not yet merged. The fix should be in the bar-/columnchart PR: #337.