NEP -R PROGRAMMING

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

6. Drawing Line and bar chart using matplotlib.

 
  
 
 6. Drawing Line and bar chart using matplotlib.

import matplotlib.pyplot as plt

# Sample data for the charts
x_values = [1, 2, 3, 4, 5]
y_values_line = [5, 3, 8, 4, 6]
y_values_bar = [2, 6, 3, 8, 5]

# Create a figure to hold both line and bar charts
plt.figure(figsize=(10, 6))

# Plot the line chart
plt.subplot(1, 2, 1)  # Create a subplot with 1 row, 2 columns, and select the first position
plt.plot(x_values, y_values_line, marker='o', linestyle='-', color='blue', label='Line Chart')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Chart Example')
plt.legend()

# Plot the bar chart
plt.subplot(1, 2, 2)  # Select the second position in the subplot
plt.bar(x_values, y_values_bar, color='red', label='Bar Chart')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Bar Chart Example')
plt.legend()

# Adjust layout for better spacing
plt.tight_layout()

# Show both charts
plt.show()