View Source Tucan.Axes (tucan v0.4.1)

Utilities for configuring plot axes.

Summary

Functions

Sets an arbitrary set of options to the given encoding axis object.

Sets the color of both :x and :y axes.

Set a specific color to the given axis.

Enables or disables both axes (x, y) at once.

Enables or disables the given axis.

Sets the axis offset (in pixels).

Sets the orientation for the given axis.

Set the title of the given axis.

Sets the title color of the given axis

Sets the x axis title.

Sets the x-axis and y-axis titles at once.

Sets the y axis title.

Types

@type axis() :: :x | :y
@type orient() :: :bottom | :top | :left | :right

Functions

Link to this function

put_options(vl, encoding, options)

View Source
@spec put_options(vl :: VegaLite.t(), encoding :: atom(), options :: keyword()) ::
  VegaLite.t()

Sets an arbitrary set of options to the given encoding axis object.

Notice that no validation is performed, any option set will be merged with the existing axis options of the given encoding.

An ArgumentError is raised if the given encoding channel is not defined.

@spec set_color(vl :: VegaLite.t(), color :: String.t()) :: VegaLite.t()

Sets the color of both :x and :y axes.

See also set_color/3.

Link to this function

set_color(vl, axis, color)

View Source
@spec set_color(vl :: VegaLite.t(), axis :: axis(), color :: String.t()) ::
  VegaLite.t()

Set a specific color to the given axis.

Examples

A scatter plot with the y-axis colored red and x-axis with a custom RGB color:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_color(:y, "red")
|> Tucan.Axes.set_color(:x, "#2A32F4")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"domainColor":"#2A32F4"},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"domainColor":"red"},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_enabled(vl, enabled)

View Source
@spec set_enabled(vl :: VegaLite.t(), enabled :: boolean()) :: VegaLite.t()

Enables or disables both axes (x, y) at once.

See also set_enabled/3

Link to this function

set_enabled(vl, axis, bool)

View Source
@spec set_enabled(vl :: VegaLite.t(), axis :: axis(), enabled :: boolean()) ::
  VegaLite.t()

Enables or disables the given axis.

Notice that axes are enabled by default.

Examples

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_enabled(:x, false)
|> Tucan.Axes.set_enabled(:y, false)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":null,"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":null,"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_offset(vl, axis, offset)

View Source
@spec set_offset(vl :: VegaLite.t(), axis :: axis(), offset :: number()) ::
  VegaLite.t()

Sets the axis offset (in pixels).

The offset indicates the amount in pixels by which the axis will be displaces from the edge of the enclosing group or data rectangle.

Examples

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_offset(:y, 10)
|> Tucan.Grid.set_enabled(false)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"grid":false},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"grid":false,"offset":10},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_orientation(vl, axis, orientation)

View Source
@spec set_orientation(vl :: VegaLite.t(), axis :: axis(), orient :: orient()) ::
  VegaLite.t()

Sets the orientation for the given axis.

Valid values for orient are:

  • :top, :bottom for the x axis
  • :left, :right for the y axis

Examples

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_orientation(:x, :top)
|> Tucan.Axes.set_orientation(:y, :right)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"orient":"top"},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"orient":"right"},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
Link to this function

set_title(vl, axis, title)

View Source
@spec set_title(vl :: VegaLite.t(), axis :: axis(), title :: String.t()) ::
  VegaLite.t()

Set the title of the given axis.

Link to this function

set_title_color(vl, axis, color)

View Source
@spec set_title_color(vl :: VegaLite.t(), axis :: axis(), color :: String.t()) ::
  VegaLite.t()

Sets the title color of the given axis

Examples

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_title_color(:x, "red")
|> Tucan.Axes.set_title_color(:y, "#F3B212")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"x":{"axis":{"titleColor":"red"},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"titleColor":"#F3B212"},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}
@spec set_x_title(vl :: VegaLite.t(), title :: String.t()) :: VegaLite.t()

Sets the x axis title.

Link to this function

set_xy_titles(vl, x_title, y_title)

View Source
@spec set_xy_titles(vl :: VegaLite.t(), x_title :: String.t(), y_title :: String.t()) ::
  VegaLite.t()

Sets the x-axis and y-axis titles at once.

@spec set_y_title(vl :: VegaLite.t(), title :: String.t()) :: VegaLite.t()

Sets the y axis title.