Data Visualization Class12 CBSE
Data Visualization Class12 CBSE
Importance:
2. Matplotlib Library
Importing Matplotlib:
3. Types of Plots
A. Line Plot
Used to represent continuous data over intervals like time, distance, etc.
Example:
Example:
C. Histogram
Used to show frequency distribution of continuous data (e.g. age, scores).
Example:
ages = [15, 16, 16, 17, 18, 15, 16, 17, 17, 16, 18]
plt.hist(ages, bins=4, color='orange', edgecolor='black')
plt.xlabel("Age")
plt.ylabel("Frequency")
plt.title("Age Distribution of Students")
plt.show()
4. Plot Customization
import pandas as pd
y = [2, 4, 6, 8, 10]
plt.legend() # Legend
plt.grid(True) # Grid
5. Saving a Plot
plt.savefig('plot.png')
6. Complete Example
x = [1, 2, 3, 4, 5]
y1 = [10, 20, 25, 30, 35]
y2 = [5, 15, 20, 25, 30]
plt.plot(x, y1, label='Line A', color='green', marker='o', linestyle='--')
plt.plot(x, y2, label='Line B', color='red', marker='s', linestyle='-.')
plt.xlabel('Time')
plt.ylabel('Values')
plt.title('Multiple Line Plot')
plt.legend()
plt.grid(True)
plt.show()
7. Summary Table
Feature Function Example
Line Plot plt.plot() plt.plot(x, y)
Bar Graph plt.bar() plt.bar(x, height)
Histogram plt.hist() plt.hist(data, bins=5)
Title plt.title() plt.title("My Plot")
Axis Labels plt.xlabel(), plt.ylabel() plt.xlabel("X")
Grid plt.grid(True)
Legend plt.legend()
Save Plot plt.savefig("file.png")