uiua-plot

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

Min°2°¤△⟜Num
Max°2°¤△⟜Num
Size°2°¤△⟜Num
BgColor⍣°3°4°¤△⟜Num
AxisWidth°[]△⟜Num
AxisColor⍣°3°4°¤△⟜Num
GridlineWidth°[]△⟜Num
GridlineColor⍣°3°4°¤△⟜Num
GridlineInterval°2°¤△⟜Num
NumberSize°[]△⟜Num
NumberColor⍣°3°4°¤△⟜Num
XLabel°[W]△⟜Char
YLabel°[W]△⟜Char
AxisLabelSize°[]△⟜Num
AxisLabelColor⍣°3°4°¤△⟜Num
PlotLabelSize°[]△⟜Num
PlotLabelColor⍣°3°4°¤△⟜Num
BarWidth°[]△⟜Num
BarLabels°[W]△⟜≡◇Char⟜Box
BarLabelSize°[]△⟜Num
BarLabelColor⍣°3°4°¤△⟜Num
DrawDots°[]△⟜Num
DotSize°[]△⟜Num
DrawLines°[]△⟜Num
LineWidth°[]△⟜Num

PlotConfig~Ppu function

|1Output?Input

Pixels per unit

Source code
Ppu ← ÷-⊃Min⊃Max Size

PlotConfig~Bounds function

|1Output?Input
Source code
Bounds ← ⊃[Min|Max]

PlotConfig~XBounds function

|1Output?Input
Source code
XBounds ← ⊢⍉Bounds

PlotConfig~YBounds function

|1Output?Input
Source code
YBounds ← ⊣⍉Bounds

Data

Data module


Data~ data boxed

Values
Color⍣°3°4°¤△⟜Num
Label°[W]△⟜Char
DrawDots°[]△⟜Num
DotSize°[]△⟜Num
DrawLines°[]△⟜Num
LineWidth°[]△⟜Num

Constants

Red constant

Literal value[0.7803921568627451 0.2666… 0.25098039215686274]

Blue constant

Literal value[0.17647058823529413 0.4392156862745098 0.7019607843137254]

Green constant

Literal value[0.2196078431372549 0.5490196078431373 0.27450980392156865]

Purple constant

Literal value[0.3764705882352941 0.25882352941176473 0.6509803921568628]

Orange constant

Literal value[0.9803921568627451 0.49411764705882355 0.09803921568627451]

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

Scatter! index macro

Create a Data instance that draws only dots

Takes a function to provide additional Data field configuration

Source code
Scatter! ← Data!(^ SmartDip‼^(°⊸DrawDots 1 °⊸DrawLines 0 New))

Line! index macro

Create a Data instance that draws only lines

Takes a function to provide additional Data field configuration

Source code
Line! ← Data!(
SmartDip‼^(
⨬◌(▽˜÷500)×>500⟜⊸±⊸⧻
°⊸DrawLines 1 °⊸DrawDots 0 New
)
^
)

Func‼ index macro

Data?XBounds

Generate a Data instance that plots a given function

The first function provides additional Data field configuration. The second function is the function to plot.

Source code
Func‼ ← (
SmartDip‼Data!^0(
/-⤚⊙∘⊙PC!(Size New)
≡⊟⟜≡₀^1˜⊂⊣⤙⍜×/⍜-(⇡⁅)÷5÷⊙⊢
Data!(°⊸DrawDots0New)
)
Data!^0
)

Func! index macro

Data?XBounds

Generate a Data instance that plots a given function

Source code
Func! ← Func‼∘^

Infer‼ index macro

?FieldGetterInferenceFunction

Infer values for a config field using a function that operates on input data

Source code
Infer‼ ← ⟜(⍜(∩♭^0|◌⍥˜∘⊸≠∞)˜∘^1)

Inherit‼ index macro

?DataConfigGetterPlotConfigGetter

Inherit defaults from a PlotConfig to the DataConfigs of some data

Source code
Inherit‼ ← ⍜˜∘Infer‼≡^0(≡⊙∘^1)

Monadic functions

AutoRound function

|1Output?Input

Round to one significant figure

Source code
AutoRound ← ⍜×⁅ₑ₁₀¯⌊⊸°ₑ₁₀

Scatter function

|1Output?Input

Create a Data instance that draws only dots

Source code
Scatter ← Scatter!∘

Line function

|1Output?Input

Create a Data instance that draws only lines

Source code
Line ← Line!∘

Background function

|1Image?PlotConfig
Source code
Background ← ∧↯⊙⬚1↙₄ PC!⊃Size BgColor

Axes function

|1Image?PlotConfig
Source code
Axes ← (
-⌊÷2⟜⇡⊸PC~AxisWidth
×◡⋅PC!⊃Min Ppu
⊙(°⊟◡⋅PC~Size)°⊟⊞-
∩(°⊚⁅▽⊸≥0▽)⊓⤚>⊸<
˜∩⬚0↙°⊟◡⋅⋅PC~Size
C ˜PC~AxisColor ⇌˜⊞↥
)

Gridlines function

|1Image?PlotConfig
Source code
Gridlines ← (
⊸PC!⊃Min Ppu
⊃(×⋅˜PC~GridlineInterval
| ˜∩+∩⇡∩°⊟◡⋅PC~Size×)
˜∩(⌵⍜⊙+◿⤙÷2)°⊟
∩⌞≤÷2◡⋅⋅PC~GridlineWidth
C ˜PC~GridlineColor ⇌˜⊞↥
)

AxisNums function

|1Image?PlotConfig
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°◌
)

CircleKernel function

|1Kernel?Size
Source code
CircleKernel ← ⁿ4↧1×2√₁₆Gaussian⤙÷40⍜(÷2+1)⁅

XKernel function

|1Kernel?Size
Source code
XKernel ← (
0.3˜∘¤↥⊸⇌˙⊞=⊸⇡⍜(÷2+1)⁅×0.3
/↥≡↻♭₂˙⊞⊟-÷2-1⟜⇡⍜(÷2+1)⌊×
)

BoxKernel function

|1Kernel?Size
Source code
BoxKernel ← ¬↯⟜⊚⍜(÷2+1)⁅×0.3

Plot function

|1Image?Data

TODO: Document this more Create a line/scatter plot with a list of Data Each Data~Values should be a list of 2D coordinates withid 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(-÷5◡⋅GridlineInterval/↧/◇⊂⍚Data~Values)
PC!Infer‼Max(+÷5◡⋅GridlineInterval/↥/◇⊂⍚Data~Values)
Inherit‼Data~DrawDots PC~DrawDots
Inherit‼Data~DotSize PC~DotSize
Inherit‼Data~DrawLines PC~DrawLines
Inherit‼Data~LineWidth PC~LineWidth

PreChart
/Stack⊸↓[
⊙⟜⊃(AxisNums|Axes|Gridlines)
/Stack⇌≡⌟SingleSeries
]
PostChart
)

BarChart function

|1Image?Data

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⟜⍚layout◡⋅PC~BarLabelSize
×÷⟜⇡◡⋅⧻ ⊢◡⋅PC~Size
# ⁅+÷2-⊙⊸⊡₁◡⋅≡◇(⧻⊢)
⁅+÷2-⊙⊸⊡₁◡⋅≡◇⧻₁
≡⬚0↙⊢◡⋅PC~Size/↥⬚0≡◇≡⌝↘
C ˜PC~BarLabelColor
)
⊙(⍜⊙(⊣PC~Size)-◡⋅⧻)

∪⌟⊂∘/Stack ⊸[⤚⋅⊙∘Bars⊙⟜⊃(AxisNums|Axes|Gridlines)]

PostChart
)

Histogram function

|1Image?Data

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

C function

|2Output?Input1Input2

Apply a color to an alpha map

Source code
C ← ⍜(⊣°⍉)×∧↯⇌◡⋅△⬚1↙₄

Stack function

|2Output?Input1Input2

Stack one RGBA image atop another

Source code
Stack ← ⍜°⍉⊂ ↧⊸↥0 ⤚÷⊃(-∪⊃×+|+⊙ט∩×⟜¬) ∩⍜(⇌°⍉)°⊂

Legend function

|2Legend?DataPlotConfig
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
)

PointsToPx function

|2Coords?PointsPlotConfig

Non-rounded non-bound-checked pixel coordinates of points

Source code
PointsToPx ← ≡⇌×⊙-∩¤˜PC!⊃Ppu Min

Dots function

|2Image?DataPlotConfig
Source code
Dots ← (
⤚⤙(⁅PointsToPx Data~Values)
⇌˜⬚0↙°⊚ ▽⊸∊♭₂⇡⟜˜∘⇌PC~Size
CircleKernel◡⋅Data~DotSize
↘¯⟜↘⌊÷2△⟜FFTConvolve
↧1C ˜Data~Color
)

Lines function

|2Image?DataPlotConfig
Source code
Lines ← (
⤚⤙(⧈∘2≡/ℂPointsToPx Data~Values)
¤/ℂ°⍉⇡⇌PC~Size
⇌/↧≡/(⌵-×↥0↧1÷∩(/+×∩⊟∩°ℂ)˜⟜⟜◡˜∘∩⌞-)
¬↥0↧1-÷10◡⋅Data~LineWidth×0.7
C ˜Data~Color
)

SingleSeries function

|2Image?DataPlotConfig

Plot a single series

Source code
SingleSeries ← /Stack/◇⊂Data!↓{
⤙₂⨬[][Lines]⊸DrawLines
⨬[][Dots]⊸DrawDots
}

SingleBars function

|2Bars?DataPlotConfig
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

|2Output?Input1Input2
Source code
Bars ← (
⍜⬚0≡Data~Values∘
≡SingleBars⊙⊸¤
˜PC~BarWidth
⁅×⇌-÷2-1⟜⇡◡⋅⧻
/Stack≡≡↻
)

ColorAutoInfer function

|2.2Output1Output2?Input1Input2
Source code
ColorAutoInfer ← (
≡⍜Data~Color⬚∞↙₄
⍜˜∘Infer‼≡Data~Color⋅(⊏◿◡⋅⧻ ⇡◡⋅⧻ DefaultColors)
)

PreChart function

|2.5Output1Output2Output3Output4Output5?Input1Input2
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

|5Output?Input1Input2Input3Input4Input5
Source code
PostChart ← (
˜PC!⊃AxisLabelColor⊃AxisLabelSize⊃XLabel YLabel
⊙∩⌞(∧⌝↘⊟⊸¯⌊÷4⟜layout)
⊡1˜△⊙◡⋅⟜⧻∩⌞(⤸1⍉⊞×)⬚1↙₄
∪⌞∘˜⊂⤸1⊙⇌∩(↻⌊÷2-⊃⊙⧻⬚0↙)
Stack˜⊂↙×1_¯1˜⇌≡⊂⬚0↙◡⋅⧻
)