EME 210
Data Analytics for Energy Systems

Visualization: One Variable

PrintPrint

Visualization: One Variable

  Read It: Visualizations with One Variable

In this lesson, you will learn about various types of plots and how to create those in Python. In particular, we will start with plots that consider one variable. If the variable that you want to plot is a categorical variable, often you will want to create a bar plot, as shown below. Here, the variable we are plotting is the majors of students that took this survey, and on the y-axis we are showing the count of those majors. This type of plot can also be considered a graphical representation of a frequency table.

seven column bar graph depicting number of students within programs of study who completed survey; As described above with results described below
Bar plot of a single categorical variable. Here, we show the major of students on the x-axis and the number of students in that major on the y-axis.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0 

You can also use bar plots to show a quantitative variable that is separated by a category. For example, the plot below shows the total number of credit hours taken by students in the survey, separated by major. We can see that PNGE students took the most credit hours in total, largely because they represent the largest major that took the survey.

seven column bar graph depicting number credit hours taken bystudents within programs of study; As described above with results described below
Bar plot of a single quantitative variable separated by categories. Here, we show the major of students on the x-axis and the total number of credits being taken by students in that major on the y-axis.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0 

Another way that you can plot quantitative data is through histograms. Histograms are similar to bar plots, but they are only used to show counts of variables. Below, we show an example histogram that plots the credit hours taken by students in the survey. Plotting a histogram can also be a great way to visualize a variable's distribution. 

8 column histogram depicting count for student credit hours as characterized above
Histogram of a single quantitative variable. Here, we show the number of credits being taken by students on the x-axis and the count (or frequency) of the number of students that are taking a given number of credits on the y-axis.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0 

Similar to histograms, box plots can be used to visualize a distribution. They can also be used to identify the 5-number summary of a quantitative variable. Below, we show a boxplot of the credit hours taken by students. We can see the minimum value, the maximum value, the median, and the first and third quantiles. Additionally, box plots will show you which values, if any, are outliers. In this plot, we do not have any outliers. 

box shaped plot depicting rectangular data range for minimum and maximum data values as described above and below
Box plot for a single quantitative variable. Here, we show the number of credits taken by each student on the y-axis and nothing on the x-axis. 
Credit: © Penn State is licensed under CC BY-NC-SA 4.0 

  Assess It: Check Your Knowledge

Knowledge Check

   FAQ