In this video, we will be talking about some
of the data distribution plots in MATLAB.
Specifically, we will talk about histogram, pie chart,
and heatmap.
We can use these plots as a way of displaying data.
Let's start off with histogram.
A histogram is a visual interpretation
of numerical data by showing the number of data points
that fall within a specified range of values.
Let's now switch to MATLAB and open out a new live script.
We will first import the data that
will be used to make the distribution plots.
To create the categorical histogram,
we will use the file outages.csv.
Let's read the file as a table.
The outages file contains data representing electrical utility
outages in the United States.
The file contains six columns, region, outage time, loss,
customers, restoration time, and cause.
Each column contains different kinds of data types.
There's categorical, floating point numeric, or datetime.
We will use the format option to specify the kind of data
each column contains.
We will now index into the first few rows of data
to see the variables.
Let's now plot a categorical histogram of the cause
variable.
Let's specify cause of outage on the x-axis, frequency
on the y-axis, and specify a title to the plot
to make it easy to read.
We can also change the appearance of the histogram.
Face color lets us change the histogram bar color
by specifying some common colors by name.
The display order option allows us to sort the bins.
For example, let's sort the bins from the largest to smallest
and change the color of the histogram to red.
Pie charts show the relative size of each value in relation
to the whole.
We will now index into the first five rows
of data from the outages file.
Let's now extract the loss column from the table.
We will now plot the pie chart of the loss
and label the slices using the pie function.
We can offset slices from the pie.
Explode is a vector or matrix of zeros and non-zeros
that correspond to loss.
Offset the second and the fourth pie
slices by setting the corresponding explode elements
to one.
We can also compare two pie charts.
We can create a 1-by-2pie tile chart layout
and display 2 pie charts that each have a title,
then display the shared legend in the style of the layout.
A heatmap is a graphical representation
of data where values are depicted by color.
Heatmaps make it easy to visualize complex data
and understand it at a glance.
We will use the heatmap function with region on the x-axis
and cause on the y-axis to create
a heatmap that shows different regions and different outage
causes.
Each cell will show how many times
each region experienced a power outage
due to a particular cause.
With 2021a of MATLAB, the next time you want to create a plot
use the Live Task for an easy and interactive experience.
First load the file patients.
To open the task, either select Create Plot
from the Task tab or type visualize in a code block.
When the task opens up, select the plot that you want.
Select Age as the x variable and Diastolic as the y variable
in the Select Data section.
You will now see the scatterplot to your right.
You can also customize the visualization.
Select Marker symbol from the dropdown
and go ahead and select the marker that you want.
The scatterplot now shows the updated symbols.
This task automatically generates MATLAB code as well.
If you want to learn more about the different types of MATLAB
plots and the examples that we used in this video,
feel free to go through the links in the description.