Tucan.Axes (tucan v0.5.0)

View Source

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.

Set the rotation angle of the given axis labels.

Enables or disables the labels of 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

axis()

@type axis() :: :x | :y

orient()

@type orient() :: :bottom | :top | :left | :right

Functions

put_options(vl, encoding, options)

@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.

set_color(vl, color)

@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.

set_color(vl, axis, color)

@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"}}

set_enabled(vl, enabled)

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

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

See also set_enabled/3

set_enabled(vl, axis, bool)

@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"}}

set_labels_angle(vl, axis, angle)

@spec set_labels_angle(vl :: VegaLite.t(), axis :: axis(), angle :: number()) ::
  VegaLite.t()

Set the rotation angle of the given axis labels.

By default, the label angle is -90 degrees for nominal and ordinal fields, and 0 degrees otherwise.

Examples

A scatter plot with the x-axis labels rotated 45 degrees:

Tucan.bar(%{x: ["Monday", "Tuesday", "Wednesday"], y: [4, 8, 2]}, "x", "y")
|> Tucan.Axes.set_labels_angle(:x, 45)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","__tucan__":{"types":{"x":"nominal","y":"quantitative"}},"data":{"values":[{"x":"Monday","y":4},{"x":"Tuesday","y":8},{"x":"Wednesday","y":2}]},"encoding":{"x":{"axis":{"labelAngle":45},"field":"x","type":"nominal"},"y":{"field":"y","type":"quantitative"}},"mark":{"fillOpacity":1,"type":"bar"}}

set_labels_enabled(vl, axis, enabled)

@spec set_labels_enabled(vl :: VegaLite.t(), axis :: axis(), enabled :: boolean()) ::
  VegaLite.t()

Enables or disables the labels of the given axis.

Examples

A scatter plot with both x-axis and y-axis labels disabled:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Axes.set_labels_enabled(:x, false)
|> Tucan.Axes.set_labels_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":{"labels":false},"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"axis":{"labels":false},"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":1,"type":"point"}}

set_offset(vl, axis, offset)

@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"}}

set_orientation(vl, axis, orientation)

@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"}}

set_title(vl, axis, title)

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

Set the title of the given axis.

set_title_color(vl, axis, color)

@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"}}

set_x_title(vl, title)

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

Sets the x axis title.

set_xy_titles(vl, x_title, y_title)

@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.

set_y_title(vl, title)

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

Sets the y axis title.