saifullahrind/DataVisualization
1
1import matplotlib.pyplot as plt2import numpy as np3 4def plot_line_chart(data):5 # Data should be a list of numerical values6 plt.plot(data, marker='o')7 plt.title("Line Chart")8 plt.xlabel("X-axis")9 plt.ylabel("Y-axis")10 plt.grid(True)11 plt.show()12 13def plot_bar_chart(categories, values):14 # Categories and values should be two lists of equal length15 plt.bar(categories, values, color='skyblue')16 plt.title("Bar Chart")17 plt.xlabel("Categories")18 plt.ylabel("Values")19 plt.show()20 21def plot_pie_chart(categories, values):22 # Categories and values should be two lists of equal length23 plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=140)24 plt.title("Pie Chart")25 plt.show()26 27def main():28 print("Welcome to the Data Visualization App!")29 print("Select the type of chart you want to create:")30 print("1. Line Chart")31 print("2. Bar Chart")32 print("3. Pie Chart")33 34 chart_type = input("Enter the number of your choice: ")35 36 if chart_type == "1":37 data = list(map(int, input("Enter the numerical data for the line chart (comma separated): ").split(',')))38 plot_line_chart(data)39 40 elif chart_type == "2":41 categories = input("Enter the categories (comma separated): ").split(',')42 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))43 plot_bar_chart(categories, values)44 45 elif chart_type == "3":46 categories = input("Enter the categories (comma separated): ").split(',')47 values = list(map(int, input("Enter the corresponding values (comma separated): ").split(',')))48 plot_pie_chart(categories, values)49 50 else:51 print("Invalid choice. Please enter a valid chart type number.")52 53if __name__ == "__main__":54 main()55 