saifullahrind/DataVisualization
1
1import matplotlib.pyplot as plt2import numpy as np3 4 5def plot_line_chart(data):6 # Data should be a list of numerical values7 plt.plot(data, marker='o')8 plt.title("Line Chart")9 plt.xlabel("X-axis")10 plt.ylabel("Y-axis")11 plt.grid(True)12 plt.show()13 14def plot_bar_chart(categories, values):15 # Categories and values should be two lists of equal length16 plt.bar(categories, values, color='skyblue')17 plt.title("Bar Chart")18 plt.xlabel("Categories")19 plt.ylabel("Values")20 plt.show()21 22def plot_pie_chart(categories, values):23 # Categories and values should be two lists of equal length24 plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=140)25 plt.title("Pie Chart")26 plt.show()27 28def main():29 print("Welcome to the Data Visualization App!")30 print("Select the type of chart you want to create:")31 print("1. Line Chart")32 print("2. Bar Chart")33 print("3. Pie Chart")34 35 chart_type = input("Enter the number of your choice: ")36 37 if chart_type == "1":38 data = list(map(int, input("Enter the numerical data for the line chart (comma separated): ").split(',')))39 plot_line_chart(data)40 41 elif chart_type == "2":42 categories = input("Enter the categories (comma separated): ").split(',')43 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))44 plot_bar_chart(categories, values)45 46 elif chart_type == "3":47 categories = input("Enter the categories (comma separated): ").split(',')48 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))49 plot_pie_chart(categories, values)50 51 else:52 print("Invalid choice. Please enter a valid chart type number.")53 54if __name__ == "__main__":55 main()56import matplotlib.pyplot as plt57 58# Sample data59x = [1, 2, 3, 4, 5]60y = [1, 4, 9, 16, 25]61 62# Plotting the data63plt.plot(x, y, label='y = x^2')64plt.title('Sample Line Plot')65plt.xlabel('X')66plt.ylabel('Y')67plt.legend()68plt.grid(True)69 70# Display the plot71plt.show()72 73import matplotlib.pyplot as plt74 75def plot_line_chart(data):76 plt.plot(data, marker='o')77 plt.title("Line Chart")78 plt.xlabel("X-axis")79 plt.ylabel("Y-axis")80 plt.grid(True)81 plt.show()82 83def plot_bar_chart(categories, values):84 plt.bar(categories, values, color='skyblue')85 plt.title("Bar Chart")86 plt.xlabel("Categories")87 plt.ylabel("Values")88 plt.show()89 90def plot_pie_chart(categories, values):91 plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=140)92 plt.title("Pie Chart")93 plt.show()94 95def main():96 print("Welcome to the Data Visualization App!")97 print("Select the type of chart you want to create:")98 print("1. Line Chart")99 print("2. Bar Chart")100 print("3. Pie Chart")101 102 chart_type = input("Enter the number of your choice: ")103 104 if chart_type == "1":105 data = list(map(int, input("Enter the numerical data for the line chart (comma separated): ").split(',')))106 plot_line_chart(data)107 108 elif chart_type == "2":109 categories = input("Enter the categories (comma separated): ").split(',')110 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))111 plot_bar_chart(categories, values)112 113 elif chart_type == "3":114 categories = input("Enter the categories (comma separated): ").split(',')115 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))116 plot_pie_chart(categories, values)117 118 else:119 print("Invalid choice. Please enter a valid chart type number.")120 121if __name__ == "__main__":122 main()123 124 