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

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. 

主站蜘蛛池模板: 石渠县| 出国| 兴隆县| 荥阳市| 遂平县| 贵德县| 温州市| 二连浩特市| 伽师县| 孝感市| 申扎县| 武邑县| 满洲里市| 龙门县| 固始县| 岱山县| 宜春市| 申扎县| 延安市| 丹凤县| 通州区| 老河口市| 祁门县| 准格尔旗| 辽源市| 秀山| 海南省| 芜湖市| 沐川县| 盘山县| 赣州市| 西充县| 布尔津县| 灵川县| 乌什县| 海晏县| 中西区| 体育| 肥乡县| 南陵县| 固阳县|