uiua-plot
PlotConfig
PlotConfig module
TODO: Document this more
The following fields can infer their values based on data:
Min
Max
GridlineInterval
The following fields provide defaults for unspecified series-specific values:DrawDots
DotSize
DrawLines
LineWidth
PlotConfig~ data boxed
PlotConfig~Ppu function
Pixels per unit
Source code
Ppu ← ÷-⊃Min⊃Max Size
PlotConfig~Bounds function
Source code
Bounds ← ⌅([⊃Min Max]|⟜[⊃Min Max]|⍜Max◌⍜Min◌⊙°⊟)
PlotConfig~XBounds function
Source code
XBounds ← ⊢⍉Bounds
PlotConfig~YBounds function
Source code
YBounds ← ⊣⍉Bounds
Data
Data module
Data~ data boxed
Constants
DefaultColors constant
Literal value
╭─
╷ 0.7803921568627451 0.2666… 0.25098039215686274 1
0.17647058823529413 0.4392156862745098 0.7019607843137254 1
0.2196078431372549 0.5490196078431373 0.27450980392156865 1
0.3764705882352941 0.25882352941176473 0.6509803921568628 1
0.9803921568627451 0.49411764705882355 0.09803921568627451 1
0 0 0 1
╯
Colors from Desmos graphing calculator
https://www.desmos.com/api/v1.7/docs/index.html#document-colors
Index macros
Func! index macro
Generate a Data
instance that plots a given function
Source code
Func! ← ( ⤚/-⊙PC!(Size New) ≡⊟⟜∵^0𝄈⊂⊣⤙⍜×/⍜-(⇡⁅)÷5÷⊙⊢ Data!(°⊸DrawDots0New))
Monadic functions
Scatter function
Create a Data
instance that draws only dots
Source code
Scatter ← Data!(°⊸DrawDots 1 °⊸DrawLines 0 New)
Line function
Create a Data
instance that draws only lines
Source code
Line ← Data!(°⊸DrawLines 1 °⊸DrawDots 0 New)
Background function
Source code
Background ← ∧↯⊙⬚1↙₄ PC!⊃Size BgColor
Axes function
Source code
Axes ← ( -⌊÷2⟜⇡⊸PC~AxisWidth ×PC!⊃Min Ppu, ⊙(°⊟PC~Size,)°⊟⊞- ∩(°⊚⁅▽⊸≥0▽)⊓⤚>⊸< ∩⬚0↙⊙:°⊟◡⋅⋅PC~Size C PC~AxisColor:⇌𝄈⊞↥)
Gridlines function
Source code
Gridlines ← ( ⊸PC!⊃Min Ppu ⊃(×PC~GridlineInterval⋅: | ∩+⊙:∩⇡∩°⊟PC~Size,×) ∩(⌵⍜⊙+◿⤙÷2)⊙:°⊟ ∩⌞≤÷2◡⋅⋅PC~GridlineWidth C PC~GridlineColor:⇌𝄈⊞↥)
AxisNums function
Source code
AxisNums ← ⬚∘( PC!⊃GridlineInterval⊃Min⊃Max⊃Ppu Size°◌ ⊓⌈⌊⤚∩⌞÷⊙⊓⟜:⊙⇌ ∩°⊟₆°⊟⍉⊟₆ ∩⊓( ⤙×▽⊸≠0⍜-(⇡+1) ⍜×⁅𝄈ⁿ10⬚0⊗@.⇌°⋕ # Round values to precision of original factor ⍚(∧⌝↘⊟⊸¯⊟.⁅÷8⟜layout) PC~NumberSize°◌⊃°⋕(×𝄈-) )∘ ⊓⍚⍉⊙⊙⍚⇌⍚⇌ ∩(♭₂∧◇(⬚0↥⬚0↙⁅⊟⊙:¯+⌊÷2⤚⧻)⊙⊙⊙[]) ↥∩⇌∩⌞⬚0↙⇌PC~Size°◌⍉ C PC~NumberColor°◌)
Plot function
TODO: Document this more
Create a line/scatter plot with a list of Data
Each Data~Values
should be a list of 2D coordinates,
stored as a single rank 2 array.
Use ⬚ fill
to provide a custom PlotConfig
.
Source code
Plot ← ( ColorAutoInfer ⊙⍣°◌PC ♭₂
PC!Infer‼GridlineInterval(AutoRound÷5-⊃/↧/↥/◇⊂⍚Data~Values) PC!Infer‼Min(-÷5GridlineInterval,/↧/◇⊂⍚Data~Values) PC!Infer‼Max(+÷5GridlineInterval,/↥/◇⊂⍚Data~Values) Inherit‼Data~DrawDots PC~DrawDots Inherit‼Data~DotSize PC~DotSize Inherit‼Data~DrawLines PC~DrawLines Inherit‼Data~LineWidth PC~LineWidth
PreChart /Stack⊸[ /Stack⇌≡SingleSeries⊙¤ ⊙⟜(AxisNums|Axes|Gridlines)] PostChart)
BarChart function
TODO: Document this more
Create a bar chart with a list of Data
Each Data~Values
should be a list of bar heights.
Use ⬚ fill
to provide a custom PlotConfig
.
Source code
BarChart ← ( ⊙⍜PC~XBounds⋅1_1 ♭₂ ⊙⍣°◌PC PC!Infer‼YBounds(⊟⊓⌞↧↥0∩(+⊸÷20)⊃/↧/↥♭⬚0≡Data~Values) PC!Infer‼(⊣GridlineInterval|AutoRound÷5/-⋅⊸YBounds) ColorAutoInfer ⊙⍜(⊢PC~GridlineInterval)⋅∞
PreChart
◠(⬚""↙⊙⊸PC~BarLabels/↥≡(⧻Data~Values) ⍚⌝↘⁅÷8⟜⍚layoutPC~BarLabelSize, ×÷⟜⇡⧻,⊢PC~Size, ⁅+÷2-⊙⊸⊡₁≡◇(⧻⊢), ≡⬚0↙⊢PC~Size,/↥⬚0≡◇≡⌝↘ C PC~BarLabelColor:) ⊙(⍜⊙(⊣PC~Size)-⧻,)
⊂⊙:/Stack ⊸[⊙::Bars⊙⟜(AxisNums|Axes|Gridlines)]
PostChart)
Histogram function
TODO: Document this more
Create a histogram with a single set of Data
Data~Values
should be a list of numbers.
Use ⬚ fill
to provide a custom PlotConfig
.
Histogram bucket intervals can be specified
through the x component of GridlineInterval
in the PlotConfig
.
Source code
Histogram ← ( ⊙⍣°◌PC PC!Infer‼(⊢GridlineInterval|AutoRound÷10-⊃/↧/↥Data~Values) PC!Infer‼XBounds(⍜÷⁅⊢GridlineInterval,⊟⊃/↧/↥Data~Values) ⍜♭₂ColorAutoInfer ⍜Data~Values( ⊢PC!⊃GridlineInterval XBounds, °⊂⍜÷(⍜-(⇡⁅+1)°⊟) ⬚0↙⧻:°⊚⊗1⊸⊞≥▽⊸≥⊙:)
⍜¤PreChart
⊙°⊸PC~BarWidth:⌈⊢×PC!⊃Ppu GridlineInterval, PC!Infer‼YBounds(⊟0⁅×1.04/↥Data~Values) PC!Infer‼(⊣GridlineInterval|AutoRound÷5/-⋅⊸YBounds) /Stack⊸[⊙::SingleBars⊙⟜(AxisNums|Axes|Gridlines)]
PostChart)
Dyadic functions
Stack function
Stack one RGBA image atop another
Source code
Stack ← ⍜°⍉⊂ ↧⊸↥0÷⊃(+×𝄐⤚¬|+⊃×(×𝄐׬)|𝄐⍜∩¬×) ∩⍜°⍉°𝄈⊂
Legend function
Source code
Legend ← ( ⊙⊸¤ ≡PC!Data!⊃⋅PlotLabelSize⊃Color⊃°◇°Label⋅PlotLabelColor ⍚(≡⊂⊓(C:≡⬚0↙⌊×3/2⊸⧻¬↯⟜⊚|C:layout))⟜: PC~PlotLabelSize⤙⊙⊓(⊢PC~Size)⊓0[]⤚≡◇(⧻⊢) ⟜⊃(⊕□𝄈▽°⊏⇌⊂◌∧(⨬⋅⊓-+₁⊓𝄈-⋅⊓1⊂: ⊙◡< ⊙+)⤙⊓:∘)⋅⋅∘ ⟜(≡◇∧≡⬚0↙≡⊟¯⌊÷2⊸+⤚≡◇(⧻⊢)⍚/◇≡(⊂⊂)¤⍉↯4↯⟜⊚) ⟜(/(⊂⊂)⍉↯4𝄈↯0𝄈⊟⊡2△,) ∧⌝↘⊟⊸¯⌊÷2)
Dots function
Source code
Dots ← ( ⤚⤙(⁅PointsToPx Data~Values) ⇌⬚0↙:°⊚ ▽⊸∊♭₂⤚⇡⇌PC~Size CircleKernel Data~DotSize, ↘¯⟜↘⌊÷2△⟜FFTConvolve ↧1C Data~Color:)
Lines function
Source code
Lines ← ( ⤚⤙(⧈∘2≡/ℂPointsToPx Data~Values) ¤/ℂ°⍉⇡⇌PC~Size ⇌/↧≡/(⌵-×↥0↧1÷∩(/+×∩⊟∩°ℂ)⤙⤙◠:∩⌞-) ¬↥0↧1-÷10Data~LineWidth,×0.7 C Data~Color:)
SingleSeries function
Plot a single series
Source code
SingleSeries ← /Stack[ ⋅◌⍥◠Dots⊸Data~DrawDots ⍥◠Lines⊸Data~DrawLines]
SingleBars function
Source code
SingleBars ← ( ⤚PC~YBounds𝄈⊙⊸Data~Values ⟜⊃(↥⊙↧°⊟)⊢ ↥⊃(↥0-↥0⊢|⌵↧0-↧0⊣|¯↧0-↧0◌) ∩×,⊙(⊣PC~Ppu,) ⬚0≡⌝↘⁅:⬚0≡↯⊙1⁅≡⊟⊙PC~BarWidth⊙, PC!⊃BarWidth Size, ⁅+÷2-⊙(⊸⊡1×÷⟜⇡⧻,⊢) ⇌⬚0↙⇌PC~Size:/↥⬚0≡≡⌝↘ C Data~Color:)
Bars function
Source code
Bars ← ( ⍜⬚0≡Data~Values∘ ≡SingleBars⊙⊸¤ PC~BarWidth: ⁅×⇌-÷2-1⟜⇡⧻, /Stack≡≡↻)
ColorAutoInfer function
Source code
ColorAutoInfer ← ( ≡⍜Data~Color⬚∞↙₄ ⍜:Infer‼≡Data~Color⋅(⊏◿⧻,⇡⧻,DefaultColors))
PreChart function
Source code
PreChart ← ( ⊙⟜Background ⟜(±⊸⧻▽>0⊸≡(⧻Data~Label) ⨬⋅⟜(°△[0⊙4]⊢PC~Size)(⤚(⍜⊙(⊣PC~Size)-⧻)⊸Legend)) ⊙(>0⊸[∩⧻PC!⊃YLabel XLabel]⟜PC~Size ⍜⊙PC~Size-×+⟜+⌊⊸÷4 PC~AxisLabelSize,))
Pentadic functions
PostChart function
Source code
PostChart ← ( PC!⊃AxisLabelColor⊃AxisLabelSize⊃XLabel YLabel: ⊙∩⌞(∧⌝↘⊟⊸¯⌊÷4⟜layout) ⊡1△:⊙(⟜⧻,)∩⌞(⤸1⍉⊞×)⬚1↙₄ ⊙𝄈⊂:⤸1⊙⇌∩(↻⌊÷2-⊃⊙⧻⬚0↙) Stack𝄈⊂↙×1_¯1⇌:≡⊂⬚0↙⧻,)