Functions and data

Loading Ebi…
type WeatherDay = {
    date: String, precipitation: Number, temp_max: Number,
    temp_min: Number, wind: Number, weather: String
}
let url = "https://raw.githubusercontent.com/vega/vega/main/docs/data/seattle-weather.csv"
let days = read<List<WeatherDay>>(url)
let ax = NumberPlane(x_range=[-10, 20, 5], y_range=[-5, 40, 5], x_length=330pt, y_length=200pt)
let dates = days.map(fn (day: WeatherDay): String { return day.date })
let points = days.map(fn (day: WeatherDay): List<Number, 2> {
    return [day.temp_min, day.temp_max]
})
let years = [2012, 2013, 2014, 2015].map(fn (year: Number): Element {
    let start = dates.bisect_left("{year}-01-01")
    let end = dates.bisect_left("{year + 1}-01-01")
    return ax.scatter(points.slice(start=start, end=end), radius=1.5pt, fill=Color("blue2"))
})
<Plot axes={ax} edge_axes={true}/>
<Text text="Daily high (°C)" position={[-165pt, -116pt]} font_size={12pt}/>
<Text text="Daily low (°C)" position={[0pt, 125pt]} font_size={12pt}/>
for observations in years {
    observations.fade_in(duration=500ms)
}
wait(1200ms)
years.fade_out(duration=500ms)

The observations fade in one year at a time. Each dot pairs the daily low and high from one of Seattle’s 1,461 weather observations between 2012 and 2015. NOAA data via Vega Datasets

read<List<WeatherDay>> accepts a project-relative path or an HTTP(S) URL. Ebi uses the URL’s path extension to select the data format. A bounded in-memory cache reuses downloads across hot reloads. Restarting the session fetches them again. In a browser, the server must allow cross-origin fetches when it’s on a different origin.

UseTo draw
Axes, NumberPlane, PolarPlane, ComplexPlaneCartesian axes, a rectangular grid, polar guides, or a complex plane. Call frame() to show it.
NumberLine, UnitIntervalA single labeled horizontal axis.
ax.plot(f), ax.plot_parametric_curve(f), ax.plot_polar_graph(f)A function, a function returning [x, y], or a radius as a function of angle in radians.
ax.plot_implicit_curve(f)A level set such as x*x + y*y - 1 = 0, with level=0 by default.
ax.plot_line_graph(points), ax.scatter(points), ax.bar(points), BarChart(values)A line, markers, or bars. Each coordinate pair is [x, y].
ax.get_area(f), ax.get_riemann_rectangles(f)Area to the axis or to bounded_function.
ax.plot_derivative_graph(f), ax.plot_antiderivative_graph(f), ax.get_secant_slope_group(f, x=1)A derivative, an integral from the lower range endpoint, or a secant with rise and run.
ax.get_lines_to_point(point), ax.get_graph_label(f, text="f", x=1), ax.get_axis_labels()Guides and annotations.
ax.get_vector(point), ax.vector_field(f), ax.streamlines(f)An arrow from the origin, arrows sampled from a vector field, or trajectories through that field.

Use ax.c2p([x, y]) to position an Ebi element from data. Use ax.p2c([x, y]) for the inverse. For a logarithmic axis, set x_log_base or y_log_base and use positive range endpoints. On a complex plane, pass [real, imaginary].

Set edge_axes=true on Plot to place the rulers and tick labels along the left and bottom edges. The grid draws behind the series.

Pass a signal to points on ax.plot_line_graph or ax.scatter to move the data. For a function plot, pass a second Number into the callback with parameter= as in the wave example. Sampled curves and contours keep the points computed at construction. You can animate the position, rotation, scale, or opacity of the resulting element.