In this segment, you will learn about two new visualisation charts, namely:
A line graph is used to present continuous time-dependent data. It accurately depicts the trend of a variable over a specified time period. Let’s see how you can plot a line chart using the Matplotlib library. You can download the Python notebook provided below to code along with the instructor.
You can use the following command to plot a line graph:
plt.plot(x_axis, y_axis)
You should be careful when using the function plt.plot
. The same function generates a scatterplot if you tweak the syntax and specify the markers. Try to run the code below to understand the difference:
y = np.random.randint(1,100, 50) plt.plot(y, 'ro') # ‘ro’ represents color (r) and marker (o)
(if you are getting an error, check the quotation marks)
If you specify the colour and marker separately, then you will get a line plot with the points marked. Try using the code provided below:
plt.plot(y, 'red', marker = 'o')
A line graph is very helpful when you want to understand the trend of a variable. Some key industries and services that rely on line graphs are financial markets, weather forecast, etc. In the video above, you also learnt how to rotate the tick labels on the axes:
plt.yticks(rotation = number) #could do for xticks as well
Let’s move on to Histograms now. A histogram is a frequency chart that records the occurrence of an entry or an element in a data set. It is useful when you want to understand the distribution of a given series. Let us learn how to plot a histogram in the video below.
As shown in the video, you can use the following command to plot a histogram:
plt.hist(input, bins = number_of_bins, edgecolor = "color", color = "color")
You can use the attributes provided to make your histogram more readable and visually appealing.
In the next segment, you will learn about another plot, namely, Box Plot.