Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling x axis and y axis with VegaLite.jl

I have plotted a scatter plot in VegaLite.jl, however, the x-axis and y-axis don't get scaled automatically like other plotting packages (plots, plotly etc.)

For example in the following example, the plot starts x-axis from 0, whereas it would make more sense to start from a value such as 125 since x-values are clustered between 150-200. The same thing applies to the y-axis. This results in a plot that has only utilized the top right section. Any ideas on how to scale the x and y axes?

using VegaLite
x = Array{Int64}([150,175,200])
y = Array{Int64}([225,250,275])

@vlplot(
    :point,
    x = x,
    y = y
)

enter image description here

like image 687
imantha Avatar asked Dec 07 '25 11:12

imantha


1 Answers

You can add a scale specification, as documented in the Vega-Lite documentation or demonstrated e.g. here in the VegaLite.jl documentation.

For example:

using VegaLite
using DataFrames

data = DataFrame(x = [150,175,200], y = [225,250,275])

data |> @vlplot(
    :point,
    x = {:x, scale = {zero = false}}, # Auto scale, without enforcing that zero be in the domain
    y = {:y, scale = {domain = (200, 300)}}, # Explicit domain
)

Resulting plot

like image 73
François Févotte Avatar answered Dec 09 '25 17:12

François Févotte