官术网_书友最值得收藏!

Polar chart

Do you remember the polar axis from mathematics class? Well, a polar chart is a diagram that is plotted on a polar axis. Its coordinates are angle and radius, as opposed to the Cartesian system of x and y coordinates. Sometimes, it is also referred to as a spider web plot. Let's see how we can plot an example of a polar chart.

First, let's create the dataset:

Let's assume you have five courses in your academic year:

subjects = ["C programming", "Numerical methods", "Operating system", "DBMS", "Computer Networks"]

2.nd you planned to obtain the following grades in each subject:

plannedGrade = [90, 95, 92, 68, 68, 90]

3.owever, after your final examination, these are the grades you got:

actualGrade = [75, 89, 89, 80, 80, 75]

Now that the dataset is ready, let's try to create a polar chart. The first significant step is to initialize the spider plot. This can be done by setting the figure size and polar projection. This should be clear by now. Note that in the preceding dataset, the list of grades contains an extra entry. This is because it is a circular plot and we need to connect the first point and the last point together to form a circular flow. Hence, we copy the first entry from each list and append it to the list. In the preceding data, the entries 90 and 75 are the first entries of the list respectively. Let's look at each step:

Import the required libraries:

import numpy as np
import matplotlib.pyplot as plt

2.repare the dataset and set up theta:

theta = np.linspace(0, 2 * np.pi, len(plannedGrade))

3.nitialize the plot with the figure size and polar projection:

plt.figure(figsize = (10,6))
plt.subplot(polar=True)

4.et the grid lines to align with each of the subject names:

(lines,labels) = plt.thetagrids(range(0,360, int(360/len(subjects))),
(subjects))

5.se the plt.plot method to plot the graph and fill the area under it:

plt.plot(theta, plannedGrade)
plt.fill(theta, plannedGrade, 'b', alpha=0.2)

6.ow, we plot the actual grades obtained:

plt.plot(theta, actualGrade)

7.e add a legend and a nice comprehensible title to the plot:

plt.legend(labels=('Planned Grades','Actual Grades'),loc=1)
plt.title("Plan vs Actual grades by Subject")

8.inally, we show the plot on the screen:

plt.show()

The generated polar chart is shown in the following screenshot:

As illustrated in the preceding output, the planned and actual grades by subject can easily be distinguished. The legend makes it clear which line indicates the planned grades (the blue line in the screenshot) and which line indicates actual grades (the orange line in the screenshot). This gives a clear indication of the difference between the predicted and actual grades of a student to the target audience. 

主站蜘蛛池模板: 吴江市| 香河县| 白山市| 吴江市| 岗巴县| 青冈县| 临邑县| 泉州市| 拜泉县| 绍兴县| 内江市| 镶黄旗| 海晏县| 延庆县| 东宁县| 长海县| 民县| 兰州市| 南华县| 永登县| 天气| 永登县| 外汇| 北安市| 自贡市| 遂溪县| 象山县| 沙河市| 遵化市| 大连市| 石柱| 铜鼓县| 汉阴县| 白朗县| 伊春市| 枣阳市| 双峰县| 汝州市| 临武县| 吉林省| 德保县|