@@ -598,248 +598,6 @@ The tree library allows the drawing diagrams with simple tree layout algorithms
598
598
599
599
# doc-style . parse-show-module (" /src/lib/tree.typ" )
600
600
601
- == Plot
602
-
603
- The library `plot` of CeTZ allows plotting data.
604
-
605
- === Types
606
-
607
- Types commonly used by function of the `plot` library:
608
- - # doc-style . show-type (" domain" ): Tuple representing a functions domain as closed interval.
609
- Example domains are: `(0, 1)` for $ [0, 1]$ or
610
- `(-calc.pi, calc.pi)` for $ [-pi , pi ]$ .
611
- - # doc-style . show-type (" axes" ): Tuple of axis names. Plotting functions taking an `axes` tuple
612
- will use those axes as their `x` and `y` axis for plotting.
613
- To rotate a plot, you can simply swap its axes, for example `("y", "x")` .
614
- - # doc-style . show-type (" mark" ): Plots feature their own set of marks. The following mark symbols are
615
- available:
616
- ```example-vertical
617
- let marks = ("+", "x", "-", "|", "o", "square", "triangle")
618
- cetz.plot.plot(size: (14, 1), x-min: 0, x-max: marks.len() + 1,
619
- x-ticks: marks.enumerate().map(((i, s)) => (i+1, raw(s))),
620
- x-tick-step: none, y-tick-step: none,
621
- x-label: none, y-label: none,
622
- {
623
- for (i, s) in marks.enumerate() {
624
- cetz.plot.add(((i + 1, 0),), mark: s, mark-style: (stroke: blue, fill: white), mark-size: .5)
625
- }
626
- })
627
- ```
628
-
629
- # doc-style . parse-show-module (" /src/lib/plot.typ" )
630
-
631
- === Legends <plot-legends>
632
- A legend for a plot will be drawn if at least one set of data with a label that is not `none` is given.
633
- The following anchors are available when placing a legend on a plot:
634
- - `north`
635
- - `south`
636
- - `east`
637
- - `west`
638
- - `north-east`
639
- - `north-west`
640
- - `south-east`
641
- - `south-west`
642
- - `inner-north`
643
- - `inner-south`
644
- - `inner-east`
645
- - `inner-west`
646
- - `inner-north-east`
647
- - `inner-north-west`
648
- - `inner-south-east`
649
- - `inner-south-west`
650
- ```example
651
- import cetz.plot
652
- plot.plot(
653
- size: (3,2),
654
- x-tick-step: none,
655
- y-tick-step: none,
656
- legend: "north", {
657
- plot.add(
658
- ((-1, -1), (1, 1)),
659
- mark: "o",
660
- label: $ f(x) $
661
- )
662
- })
663
- ```
664
-
665
- ==== Styling
666
- *Root:* `legend`
667
- ===== Keys
668
- # doc-style . show-parameter-block (" orientation" , (" direction" ), default : ttb , [
669
- The direction the legend items get laid out to.
670
- ])
671
- # doc-style . show-parameter-block (" default-position" , (" string" , " coordinate" ), default : " legend.north-east" , [
672
- The default position the legend gets placed at.
673
- ])
674
- # doc-style . show-parameter-block (" layer" , (" number" ), default : 1 , [
675
- The layer index the legend gets drawn at, see on-layer.
676
- ])
677
- # doc-style . show-parameter-block (" fill" , (" paint" ), default : rgb (255 ,255 ,255 ,200 ), [
678
- The legends frame background color.
679
- ])
680
- # doc-style . show-parameter-block (" stroke" , (" stroke" ), default : black , [
681
- The legends frame stroke style.
682
- ])
683
- # doc-style . show-parameter-block (" padding" , (" float" ), default : .1 , [
684
- The legends frame padding, that is the distance added between its items and its frame.
685
- ])
686
- # doc-style . show-parameter-block (" offset" , (" tuple" ), default : (0 ,0 ), [
687
- An offset tuple (x and y coordinates) to add to the legends position.
688
- ])
689
- # doc-style . show-parameter-block (" spacing" , (" number" ), default : .1 , [
690
- The spacing between the legend position and its frame.
691
- ])
692
- # doc-style . show-parameter-block (" item.spacing" , (" number" ), default : .05 , [
693
- The spacing between two legend items in canvas units.
694
- ])
695
- # doc-style . show-parameter-block (" item.preview.width" , (" number" ), default : .75 , [
696
- The width of a legend items preview picture, a small preview of the graph the legend item belongs to.
697
- ])
698
- # doc-style . show-parameter-block (" item.preview.height" , (" number" ), default : .3 , [
699
- The height of a legend items preview picture.
700
- ])
701
- # doc-style . show-parameter-block (" item.preview.margin" , (" number" ), default : .1 , [
702
- Margin between the preview picture and the item label.
703
- ])
704
-
705
-
706
- # doc-style . parse-show-module (" /src/lib/plot/line.typ" )
707
- # doc-style . parse-show-module (" /src/lib/plot/contour.typ" )
708
- # doc-style . parse-show-module (" /src/lib/plot/boxwhisker.typ" )
709
- # doc-style . parse-show-module (" /src/lib/plot/bar.typ" )
710
- # doc-style . parse-show-module (" /src/lib/plot/annotation.typ" )
711
- # doc-style . parse-show-module (" /src/lib/plot/sample.typ" )
712
-
713
- === Examples
714
-
715
- ```example
716
- import cetz.plot
717
- plot.plot(size: (3,2), x-tick-step: calc.pi, y-tick-step: 1,
718
- x-format: v => $#{v/calc.pi} pi$, {
719
- plot.add(domain: (0, 4*calc.pi), calc.sin,
720
- samples: 15, line: "hvh", style: (mark: (stroke: blue)))
721
- plot.add(domain: (0, 4*calc.pi), calc.sin)
722
- })
723
- ```
724
-
725
- ```example
726
- import cetz.plot
727
- import cetz.palette
728
-
729
- // Let ticks point outwards by giving them negative length
730
- set-style(axes: (tick: (length: -.2, minor-length: -.1)))
731
-
732
- // Plot something
733
- plot.plot(size: (3,3), x-tick-step: 1, x-minor-tick-step: .2,
734
- y-tick-step: 1, y-minor-tick-step: .2, {
735
- let z(x, y) = {
736
- (1 - x/2 + calc.pow(x,5) + calc.pow(y,3)) * calc.exp(-(x*x) - (y*y))
737
- }
738
- plot.add-contour(x-domain: (-2, 3), y-domain: (-3, 3),
739
- z, z: (.1, .4, .7), fill: true)
740
- })
741
- ```
742
-
743
- === Styling <plot.style>
744
-
745
- The following style keys can be used (in addition to the standard keys)
746
- to style plot axes. Individual axes can be styled differently by
747
- using their axis name as key below the `axes` root.
748
-
749
- ```typc
750
- set-style(axes: ( /* Style for all axes */ ))
751
- set-style(axes: (bottom: ( /* Style axis "bottom" */)))
752
- ```
753
-
754
- Axis names to be used for styling:
755
- - School-Book and Left style:
756
- - `x` : X-Axis
757
- - `y` : Y-Axis
758
- - Scientific style:
759
- - `left` : Y-Axis
760
- - `right` : Y2-Axis
761
- - `bottom` : X-Axis
762
- - `top` : X2-Axis
763
-
764
- # doc-style . parse-show-module (" /src/lib/axes.typ" )
765
-
766
- ==== Default `scientific` Style
767
- # raw (repr (axes . default-style-scientific ))
768
-
769
- ==== Default `school-book` Style
770
- # raw (repr (axes . default-style-schoolbook ))
771
-
772
- == Chart
773
-
774
- With the `chart` library it is easy to draw charts.
775
-
776
- # doc-style . parse-show-module (" /src/lib/chart/barchart.typ" )
777
- # doc-style . parse-show-module (" /src/lib/chart/columnchart.typ" )
778
- # doc-style . parse-show-module (" /src/lib/chart/piechart.typ" )
779
- # doc-style . parse-show-module (" /src/lib/chart/boxwhisker.typ" )
780
-
781
- === Examples -- Bar Chart <barchart-examples>
782
- ```example-vertical
783
- import cetz.chart
784
- // Left - Basic
785
- let data = (("A", 10), ("B", 20), ("C", 13))
786
- group(name: "a", {
787
- chart.barchart(size: (4, 3), data)
788
- })
789
- // Center - Clustered
790
- let data = (("A", 10, 12, 22), ("B", 20, 1, 7), ("C", 13, 8, 9))
791
- group(name: "b", anchor: "south-west", {
792
- anchor("default", "a.south-east")
793
- chart.barchart(size: (4, 3), mode: "clustered", value-key: (1,2,3), data)
794
- })
795
- // Right - Stacked
796
- let data = (("A", 10, 12, 22), ("B", 20, 1, 7), ("C", 13, 8, 9))
797
- group(name: "c", anchor: "south-west", {
798
- anchor("default", "b.south-east")
799
- chart.barchart(size: (4, 3), mode: "stacked", value-key: (1,2,3), data)
800
- })
801
- ```
802
-
803
- === Examples -- Column Chart <columnchart-examples>
804
-
805
- ==== Basic, Clustered and Stacked
806
- ```example-vertical
807
- import cetz.chart
808
- // Left - Basic
809
- let data = (("A", 10), ("B", 20), ("C", 13))
810
- group(name: "a", {
811
- chart.columnchart(size: (4, 3), data)
812
- })
813
- // Center - Clustered
814
- let data = (("A", 10, 12, 22), ("B", 20, 1, 7), ("C", 13, 8, 9))
815
- group(name: "b", anchor: "south-west", {
816
- anchor("default", "a.south-east")
817
- chart.columnchart(size: (4, 3), mode: "clustered", value-key: (1,2,3), data)
818
- })
819
- // Right - Stacked
820
- let data = (("A", 10, 12, 22), ("B", 20, 1, 7), ("C", 13, 8, 9))
821
- group(name: "c", anchor: "south-west", {
822
- anchor("default", "b.south-east")
823
- chart.columnchart(size: (4, 3), mode: "stacked", value-key: (1,2,3), data)
824
- })
825
- ```
826
-
827
- === Styling
828
-
829
- Charts share their axis system with plots and therefore can be
830
- styled the same way, see @plot.style .
831
-
832
- ==== Default `barchart` Style
833
- # raw (repr (chart . barchart-default-style ))
834
-
835
- ==== Default `columnchart` Style
836
- # raw (repr (chart . columnchart-default-style ))
837
-
838
- ==== Default `boxwhisker` Style
839
- # raw (repr (chart . boxwhisker-default-style ))
840
-
841
- ==== Default `piechart` Style
842
- # raw (repr (chart . piechart-default-style ))
843
601
844
602
== Palette <palette>
845
603
0 commit comments