Equana

Back to Tutorials

Creating Charts and Plots

Visualize data with line, bar, scatter, and more

Run AllReset

Equana includes a comprehensive plotting library for creating visualizations directly in your notebook. Charts are rendered inline using Plotly.js, supporting line plots, bar charts, scatter plots, histograms, and pie charts — all with customizable labels, legends, and styling.

In this tutorial, you'll learn to create and customize charts, building from simple plots to complete visualizations. Variables persist between cells, so you can build on previous examples as you progress.

Line Plots

The plot() function is the most common way to visualize data. With a single argument, it plots y-values against indices 1, 2, 3, etc. With two arguments, it pairs x and y values.

Code [1]Run
# Simple line plot with automatic x-values
y = [1, 4, 9, 16, 25]
plot(y)
title("Squares")

Explicit X and Y Data

For more control, provide both x and y data. This is useful for plotting mathematical functions.

Code [2]Run
# Create x values from 0 to 2π
x = linspace(0, 2*pi, 50)

# Plot sine wave
plot(x, sin(x))
title("Sine Wave")
xlabel("Angle (radians)")
ylabel("Amplitude")

Multiple Data Series

Multiple plot() calls add data series to the same chart. Use legend() to label each series. Note that the x variable from the previous cell is still available.

Code [3]Run
# Plot both sine and cosine using the same x values
plot(x, sin(x))
plot(x, cos(x))

# Add a legend to identify each series
legend("sin(x)", "cos(x)")
title("Trigonometric Functions")

Chart Types

Beyond line plots, Equana supports bar charts, scatter plots, histograms, and pie charts.

FunctionDescriptionExample
plot(x, y)Line chartplot(x, sin(x))
bar(x, y)Bar chartbar([1, 2, 3, 4])
scatter(x, y)Scatter plotscatter(x, y)
histogram(data, bins)Histogramhistogram(randn(100, 1))
pie(data)Pie chartpie([30, 20, 50])

Bar Charts

Bar charts are ideal for categorical data or comparing discrete values.

Code [4]Run
# Monthly sales data
values = [25, 40, 30, 55, 45]
bar(values)

title("Monthly Sales")
xlabel("Month")
ylabel("Units Sold")

Scatter Plots

Scatter plots show the relationship between two variables without connecting the points.

Code [5]Run
# Generate random data points
x_scatter = rand(30, 1) * 10
y_scatter = rand(30, 1) * 10

scatter(x_scatter, y_scatter)
title("Random Scatter")
xlabel("X Values")
ylabel("Y Values")

Histograms

Histograms show the distribution of data. You can optionally specify the number of bins.

Code [6]Run
# Generate normally distributed data
data = randn(500, 1)

# Create histogram with default bins
histogram(data)

title("Normal Distribution")
xlabel("Value")
ylabel("Frequency")

Pie Charts

Pie charts show proportions of a whole.

Code [7]Run
# Market share data
shares = [35, 25, 20, 15, 5]

pie(shares)
title("Market Share")
legend("Product A", "Product B", "Product C", "Product D", "Other")

Labels and Titles

Add context to your charts with titles, axis labels, legends, and text annotations.

FunctionDescriptionExample
title(str)Set chart titletitle("My Chart")
xlabel(str)Set x-axis labelxlabel("Time (s)")
ylabel(str)Set y-axis labelylabel("Value")
legend("a", "b", ...)Add legendlegend("sin", "cos")
text(x, y, str)Add text annotationtext(2, 5, "Peak")

Text Annotations

Use text(x, y, str) to place labels at specific data coordinates.

Code [8]Run
# Plot sine wave and annotate key points
x = linspace(0, 2*pi, 50)
plot(x, sin(x))

# Add text at specific coordinates
text(pi/2, 1, "Maximum")
text(3*pi/2, -1, "Minimum")

title("Annotated Sine Wave")

Axis Control

Control axis ranges, tick marks, and grid lines for precise chart formatting.

FunctionDescriptionExample
xlim([min, max])Set x-axis limitsxlim([0, 10])
ylim([min, max])Set y-axis limitsylim([-1, 1])
axis([xmin, xmax, ymin, ymax])Set all limitsaxis([0, 10, -1, 1])
xticks(values)Set x tick positionsxticks([0, 5, 10])
yticks(values)Set y tick positionsyticks([-1, 0, 1])
grid("on"/"off")Toggle grid linesgrid("on")
Code [9]Run
# Plot with custom axis limits and grid
plot(x, sin(x))

# Set custom axis limits
xlim([0, 2*pi])
ylim([-1.5, 1.5])

# Enable grid
grid("on")

title("Sine with Custom Limits and Grid")

Custom Tick Marks

Control exactly where tick marks appear on the axes.

Code [10]Run
# Plot with custom tick positions
plot(x, sin(x))

# Set custom tick positions
xticks([0, pi/2, pi, 3*pi/2, 2*pi])
yticks([-1, -0.5, 0, 0.5, 1])

title("Custom Tick Marks")

Figures and Subplots

Create multiple separate charts with figure(), or arrange charts in a grid with subplot().

FunctionDescriptionExample
figure(n)Create/switch to figurefigure()
subplot(rows, cols, idx)Create subplot gridsubplot(2, 2, 1)
hold("on"/"off")Overlay multiple plotshold("on")
yyaxis("left"/"right")Dual y-axis controlyyaxis("right")
clfClear current figureclf()
close(fig)Close figureclose()

Multiple Figures

Use figure() to start a new, separate chart.

Code [11]Run
# First figure - line plot
plot([1, 2, 3, 4])
title("Figure 1: Linear")

# Start a new figure
figure()

# Second figure - bar chart (separate from the first)
bar([4, 3, 2, 1])
title("Figure 2: Bar Chart")

Subplot Grids

Use subplot(rows, cols, index) to create a grid of charts. The index is 1-based and counts in row-major order.

Code [12]Run
# Create a 2x2 grid of charts

# Top-left (position 1)
subplot(2, 2, 1)
plot([1, 4, 9, 16])
title("Line")

# Top-right (position 2)
subplot(2, 2, 2)
bar([3, 7, 2, 5])
title("Bar")

# Bottom-left (position 3)
subplot(2, 2, 3)
scatter(rand(20, 1), rand(20, 1))
title("Scatter")

# Bottom-right (position 4)
subplot(2, 2, 4)
histogram(randn(100, 1))
title("Histogram")

Advanced Features

Dual Y-Axis Charts

Compare data with different scales using yyaxis() to plot on left and right y-axes.

Code [13]Run
# Create x values
x = linspace(0, 10, 50)

# Plot on left y-axis (default)
plot(x, sin(x))
ylabel("Sine")

# Switch to right y-axis
yyaxis("right")
plot(x, x .^ 2)
ylabel("Quadratic")

title("Dual Y-Axis Chart")
xlabel("X")

Overlaying Different Chart Types

Use hold("on") to overlay different chart types on the same axes.

Code [14]Run
# Line plot
plot([1, 2, 3, 4, 5])

# Keep current chart and add bar overlay
hold("on")
bar([0.5, 1, 1.5, 2, 2.5])

legend("Line", "Bar")
title("Mixed Chart Types")

Complete Example

Let's put it all together with a comprehensive visualization combining multiple features.

Code [15]Run
# Generate data
x = linspace(0, 4*pi, 100)
y1 = sin(x)
y2 = cos(x)

# Create plot with multiple series
plot(x, y1)
plot(x, y2)

# Add labels and legend
title("Trigonometric Functions")
xlabel("Angle (radians)")
ylabel("Value")
legend("sin(x)", "cos(x)")

# Customize axis
xlim([0, 4*pi])
ylim([-1.2, 1.2])

# Add grid
grid("on")

Statistical Analysis Visualization

Using subplots to show data distribution alongside summary statistics.

Code [16]Run
# Generate sample data
data = randn(200, 1) * 15 + 50

# Create 2x1 subplot grid
subplot(2, 1, 1)
histogram(data, 15)
title("Distribution of Values")
xlabel("Value")
ylabel("Count")

subplot(2, 1, 2)
bar([mean(data), min(data), max(data)])
title("Summary Statistics")
legend("Mean", "Min", "Max")

Summary

You've learned how to create and customize charts in Equana:

Plotting Functions

  • plot(x, y) — Line charts for continuous data
  • bar(x, y) — Bar charts for categorical data
  • scatter(x, y) — Scatter plots for relationships
  • histogram(data) — Distribution visualization
  • pie(data) — Proportional data

Customization

  • Labels: title(), xlabel(), ylabel(), legend(), text()
  • Axes: xlim(), ylim(), axis(), xticks(), yticks(), grid()
  • Layout: figure(), subplot(), hold(), yyaxis()

Tips

  • Multiple plot() calls automatically merge into one chart
  • Use figure() to start a new, separate chart
  • Different chart types auto-separate unless you use hold("on")
  • Variables persist between cells — reuse x, data, etc.

Further Reading

Workbench

Clear
No variables in workbench

Next Steps