At My Fingertips

An area chart is similar to a bar chart. It visualizes a sequence of values. Each value determines the height of the area at a particular point. The values are represented at evenly spaced points along the x-axis.

In this activity we will develop the following function to create an area chart:

```
def area_chart(
values: list[float], y_min: float, y_max: float, width: float, height: float
) -> Graphic:
```

The parameters have the following meaning:

**values**-- the list of values to represent**y_min**-- the value at the bottom end of the y-axis**y_max**-- the value at the top end of the y-axis**width**-- the width of the chart**height**-- the height of the chart

We can call the function as follows:

`save_graphic("example-chart.png", area_chart([5, 10, 5, 20, 15], 0, 30, 200, 100))`

This produces the following chart:

We can decompose an area chart into vertical slices. Horizontally, each slice goes from one data point to the next data point. Vertically, each slice consists of a right triangle sitting above a rectangle.

The height of the rectangle is the minimum of the two data points. The height of the triangle corresponds to the distance between the two data points.

Loading...

Loading...

You learned how to compose an area chart from rectangles and right triangles.

This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Simple Area Chart

PyTamaro is a project created by theÂ Lugano Computing Education Research LabÂ at theÂ Software InstituteÂ ofÂ USI

Privacy Policy â˘ Platform Version b744b47 (Tue, 08 Oct 2024 16:30:14 GMT)