Introduction to Data Science for Screen Reader Users

Introduction to Programming with Audio Graph Library

In data science, if you can flexibly assemble the processes of preparing the necessary data for analysis, processing the data to make it easier to analyze, and analyzing it using appropriate methods, all in programming rather than using separate tools, more efficient and advanced analysis work is possible. In this section, we will learn how to handle audio graphs in Python programming. Through examples using various data, let’s get familiar with understanding data through audio graphs.

Preparation of Audio Graph Library

If you are using Google Colab, execute the !pip command as follows to install the library. This content is primarily written assuming a Google Colab environment, but if you are using a command prompt environment, you can install it without the ! mark.

!pip install -q audio-plot-lib # Library installation

Next, to enable the audio graph library, execute the import command as follows.

import audio_plot_lib # Library import

Basic Usage of Audio Graph Library

First, we will explain the simple usage by displaying exactly the same content as you tried in Desmos, but with Python’s audio graph library. Unlike Desmos, you need to define the data you want to graph, rather than describing the formula. As a trial, let’s define data in an inversely proportional relationship where y decreases from 10 to 0 as x increases from 0 to 5.

x = [0, 1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2, 0]
print(f"x = {x} y = {y}")

The execution result should look something like this.

x = [0, 1, 2, 3, 4, 5] y = [10, 8, 6, 4, 2, 0]

Then, execute the following code to convert the defined x and y data into an audio graph. In addition, to explain the audio graph that will be output in advance, the execution result area has three points lined up: a basic explanation of the audio graph, the actual drawn graph, and a slider for checking values. The basic explanation of the audio graph is written in English, but it’s okay to skip it as it only describes the content that will be explained later.

There are two ways to check the audio graph. The first method is to move the slider to check. By moving the slider, the corresponding x and y values and the sound of the y value as pitch are played according to the position. Move the slider left and right to check the distribution of data. The second method is a more interactive way to check. If you can operate the mouse cursor with a mouse or touchpad, try moving the mouse cursor. When the mouse cursor overlaps the displayed graph, the voice “Enter graph” is played. In this state, if you move the mouse cursor as if tracing over the graph, you can check the audio graph just like when moving the slider. You can also read out values by clicking.

Although the prior explanation was long, let’s execute the following code and try it out. Please note that depending on your environment, nothing may be displayed only for the first time. If nothing is displayed after execution, please try executing the same code again.

audio_plot_lib.interactive.plot(x=x, y=y)

As we have done in previous chapters, you can follow the steps below to check the execution results:

  1. Press Cntl+Enter on the cell where you entered the program to run it.
  2. Press NVDA+Space key to switch to browse mode.
  3. Press the down arrow key several times to move to a location where you can read “clickable slider”.
  4. Press the space bar to switch to focus mode and make the slider movable.
  5. Press the left and right keys several times to confirm the audio playback of the values of x and y and the corresponding pitch.
  6. Press NVDA+Space key to switch back to browse mode.
  7. Press Shift+E to return to the code cell where you entered the program.
  8. Press NVDA+Space key to switch back to focus mode.

Example of execution results

Were you able to check the sound that changes in inverse proportion by operating the audio graph of the execution results? The usability is slightly different from Desmos, but the basic principle of checking the values of data by pitch is the same.

Next, let’s also create an audio graph for the quadratic curve that we tried in Desmos. First, we define the data.

x = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
y = [25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25]
print(f"x = {x} y = {y}")

The execution result should look like this.

x = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] y = [25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25]

Next, we create an audio graph from the data.

audio_plot_lib.interactive.plot(x=x, y=y)

Example of execution results

Could you interpret from the change in sound that it is a quadratic curve that is convex downward?

There is also a feature to play audio continuously without key operation, as we tried in Desmos. This is useful when you want to quickly check data arranged in a time series. Let’s try playing the quadratic curve data from earlier. After the announcement, the playback of the audio graph, which converts the magnitude of the values into pitch, will start.

audio_plot_lib.playable.plot(y, duration=100)  # x cannot be specified. Reducing the duration will shorten the interval between sounds and speed up the playback

Example of execution results

These are the basic features of the audio graph library. The audio graph library also has various options, such as changing detailed parameters like volume. There is no need to check it right away, but if you want to use it more deeply or if you need to give feedback to the developer, please refer to the library’s home page.

Audio Graph of Various Data

In Desmos and the basic usage explanation above, we only dealt with mathematical graphs. Let’s use the feature of freely combining with Python programming to convert familiar data into audio graphs and get used to handling audio graphs.

Relationship between Height and Weight

Let’s examine the relationship between height and weight from 1 to 18 years old using an audio graph. We will use the data from 2018, which can be obtained from the Japanese Government Statistics Portal Site.

First, let’s define the data for the average height and weight for each age.

height_male = [79.7,  88.6,  96. , 101.2, 110. , 115.6, 122. , 127.8, 131.8, 138.4, 145.7, 153.1, 160.3, 165.2, 168. , 173.9, 169.2, 170] # average height of males from 1 to 18 years old
weight_male = [10.4, 12.6, 14.2, 15.4, 18.2, 20.4, 24.2, 26.6, 29.1, 33.8, 38.8, 43.4, 50.4, 51. , 57.9, 62.6, 57.3, 61.1] # average weight of males from 1 to 18 years old
height_female = [77.2,  87.5,  96.1, 102.3, 109.3, 114.8, 119.6, 125.7, 134.4, 140.6, 146.6, 150.1, 154.6, 154.9, 158.2, 156.6, 154.8, 157.4] # average height of females from 1 to 18 years old
weight_female = [10.2, 12.3, 14.6, 15.9, 18.1, 20.3, 22.3, 26. , 29.7, 33.7, 37.1, 41.9, 47.2, 48.7, 49.5, 49.9, 47.2, 50.1] # average weight of females from 1 to 18 years old

This time, I would like to turn the data of both males and females into an audio graph at the same time. To do this, a bit of ingenuity is necessary, and we need to define new label data to indicate whether each data is for males or females.

Let’s prepare the data for the graph as follows:

x = height_male + height_female  # concatenate the arrays containing the height data for each of males and females
y = weight_male + weight_female  # concatenate the arrays containing the weight data for each of males and females
label = [0]*len(height_male) + [1]*len(height_female)  # define the label for males as 0 and for females as 1
print(f"x = {x}\ny = {y}\nlabel = {label}")

Convert the data to an audio graph. You should see that the number of sliders has increased to two, according to the two types of data, male and female. By operating each slider, you can check the audio graph for both males and females. If you are checking with a mouse cursor, you can switch the data to be checked by double-clicking.

audio_plot_lib.interactive.plot(x=x, y=y, label=label)

Example of execution results

Could you somewhat understand the gentle growth curve that represents the relationship between height and weight? Also, did you notice that while there is not much difference between males and females until the early teens, the difference starts to show in the latter half?

Relationship between Precipitation and Temperature

Let’s create an audio graph of the relationship between precipitation and temperature (commonly known as the rain-temperature chart) in a certain area as used in the field of meteorology, and try to understand its characteristics.

First, let’s define the data. The data on precipitation and temperature is based on the Japan Meteorological Agency’s site. We will use the normal values from 1991 to 2020 in Tokyo.

month = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]   # x-axis values from January to December
rain = [59.7, 56.5, 116.0, 133.7, 139.7, 167.8, 156.2, 154.7, 224.9, 234.8, 96.3, 57.9]  # Precipitation from January to December
temperature = [5.4, 6.1, 9.4, 14.3, 18.8, 21.9, 25.7, 26.9, 23.3, 18.0, 12.5, 7.7]  # Average temperature from January to December

Let’s prepare the data for the graph.

x = month + month
y = rain + temperature
label = [0]*len(rain) + [1]*len(temperature) # define the label for precipitation as 0, and for temperature as 1

Convert the data into an audio graph. Like the audio graph of weight and height, let’s compare the audio graphs while switching the data to be confirmed. This time, because the range of values for precipitation and temperature data are different, we enable the multiple_axes option to create audio graphs that fit the range of each value.

audio_plot_lib.interactive.plot(x=x, y=y, label=label, multiple_axes=True)

Example of execution results

Number of COVID-19 Cases

Finally, let’s check the trend of COVID-19 infection numbers with an audio graph. We will directly load and use the latest data published by the Ministry of Health, Labour and Welfare.

First, let’s load the data.

import pandas as pd  # Import a library to handle tabular data (details omitted)
df = pd.read_csv("https://covid19.mhlw.go.jp/public/opendata/newly_confirmed_cases_daily.csv")  # Fetch the data published by the Ministry of Health, Labour and Welfare
y = df[df.Prefecture == "ALL"]["Newly confirmed cases"].rolling(7).mean().values[7::7].tolist()  # Extract the average value of the number of new infections nationwide every week

print(f"Data of newly confirmed COVID-19 cases every week from {df.Date.min()} to {df.Date.max()}\ny = {y}")

Let’s convert the data into an audio graph. This time, we’ll just play the time-series data as it is.

audio_plot_lib.playable.plot(y)

Example of execution results

Could you understand the situation of gradually increasing while repeating several waves, as you hear in the news? (As of August 2021)

Summary of This Section

In this section, we learned how to handle audio graphs using Python programming. We started with the basics of audio graph libraries and then proceeded to create and interpret audio graphs using various datasets. We explored the relationship between height and weight, precipitation and temperature, and the progression of COVID-19 cases, converting real-world data into audio graphs and attempting to understand their characteristics.

Through these exercises, we were able to get a glimpse of the skill of understanding data characteristics using audio graphs, taking the first step towards a deeper understanding of data science.


Next

Home