Untitled
unknown
plain_text
19 days ago
1.2 kB
4
Indexable
Never
import matplotlib.pyplot as plt import pandas as pd # Sample data for Honeywell, 3M, and General Electric stock prices over 6 months data = { 'Date': ['2024-01-01', '2024-02-01', '2024-03-01', '2024-04-01', '2024-05-01', '2024-06-01'], 'Honeywell (HON)': [200.50, 205.60, 210.00, 215.40, 220.10, 225.30], '3M (MMM)': [150.30, 152.10, 155.00, 157.50, 160.00, 162.50], 'General Electric (GE)': [105.20, 107.00, 109.50, 112.00, 114.50, 117.00] } # Convert data to DataFrame df = pd.DataFrame(data) # Convert the Date column to datetime format df['Date'] = pd.to_datetime(df['Date']) # Plot the data plt.figure(figsize=(10, 6)) plt.plot(df['Date'], df['Honeywell (HON)'], label='Honeywell (HON)', marker='o') plt.plot(df['Date'], df['3M (MMM)'], label='3M (MMM)', marker='o') plt.plot(df['Date'], df['General Electric (GE)'], label='General Electric (GE)', marker='o') # Add labels and title plt.title('Stock Price Comparison: Honeywell, 3M, and General Electric', fontsize=14) plt.xlabel('Date', fontsize=12) plt.ylabel('Stock Price (USD)', fontsize=12) plt.xticks(rotation=45) plt.grid(True) # Show the legend plt.legend() # Display the plot plt.tight_layout() plt.show()
Leave a Comment