DSV - Module-5 Exercise Problems
DSV - Module-5 Exercise Problems
DSV - Module-5 Exercise Problems
Question 1: Write python code to Visualize Water Usage using Pie Chart and explain
various attributes. (use your own sample data)
Question 2: Write python code to Visualize Movie Comparison using a Bar Plot and explain
various attributes. (use your own sample data)
Question 3: Write python code to Visualize Restaurant Performance using Stacked Bar Plot
and explain various attributes. (use your own sample data)
Question 4: Write python code for Comparing Smartphone Sales Units Using a Stacked Area
Chart and explain various attributes. (use your own sample data)
Question 5: Write python code to Visualize Intelligence Quotient Units using a Histogram
and a Box Plot and explain various attributes. (use your own sample data)
Question 6: Write python code to Visualize Correlation between Various Animals Using a
Scatter Plot and explain various attributes. (use your own sample data)
Matplotlib Simple Line Plot
In this example, a simple line chart is generated using NumPy to define data values. The x-values are evenly
spaced points, and the y-values are calculated as twice the corresponding x-values.
We can see in the above output image that there is no label on the x-axis and y-axis. Since labeling is
necessary for understanding the chart dimensions. In the following example, we will see how to add labels,
Ident in the charts.
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Add annotations
for i, (xi, yi) in enumerate(zip(x, y)):
plt.annotate(f'({xi}, {yi})', (xi, yi), textcoords="offset
points", xytext=(0, 10), ha='center')
# Display grid
plt.grid(True)
x = np.array([1, 2, 3, 4])
y = x*2
plt.plot(x, y)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Any suitable title")
plt.show() # show first chart
x = np.array([1, 2, 3, 4])
y = x*2
x1 = [2, 4, 6, 8]
y1 = [3, 5, 7, 9]
plt.xlabel("X-axis data")
plt.ylabel("Y-axis data")
plt.title('multiple plots')
plt.show()
x = np.array([1, 2, 3, 4])
y = x*2
plt.plot(x, y)
x1 = [2, 4, 6, 8]
y1 = [3, 5, 7, 9]
Following is a simple example of the bar plot, which represents the number of students
enrolled in different courses of an institute.
import numpy as np
import matplotlib.pyplot as plt
plt.xlabel("Courses offered")
plt.ylabel("No. of students enrolled")
plt.title("Students enrolled in different courses")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
# Adding Xticks
plt.xlabel('Branch', fontweight ='bold', fontsize = 15)
plt.ylabel('Students passed', fontweight ='bold', fontsize = 15)
plt.xticks([r + barWidth for r in range(len(IT))],
['2015', '2016', '2017', '2018', '2019'])
plt.legend()
plt.show()
N = 5
plt.ylabel('Contribution')
plt.title('Contribution by the teams')
plt.xticks(ind, ('T1', 'T2', 'T3', 'T4', 'T5'))
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('boys', 'girls'))
plt.show()