Week 2 Data visualization¶
In [1]:
import matplotlib.pyplot as plt
import numpy as np
# Generate sample data: Monthly sales data for a year
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
sales = np.random.randint(50, 150, size=12) # Random sales between 50 and 150 units
# Plotting the data
plt.figure(figsize=(10,6))
plt.plot(months, sales, marker='o', linestyle='-', color='b')
plt.title('Monthly Sales Data')
plt.xlabel('Month')
plt.ylabel('Sales Units')
plt.grid(True)
plt.show()
Fig 1.0 Line graph
In [1]:
import matplotlib.pyplot as plt
labels =['Python', 'Jave', 'Html', 'C++', 'Javascript']
data = [95, 80,65,80, 90]
explode = [0.0, 0.0, 0.1, 0.0, 0.0]
plt.pie(data, labels=labels, explode = explode)
plt.show()
Fig 1.1 Pie Diagram
In [2]:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([2020, 2022, 2023, 2024, 2025])
y1 = np.array([3.5, 3.2, 4.5, 5.3, 5.1])
y2 = np.array([3.1, 3.5, 5.5, 5, 4.1])
y3 = np.array([2.1, 4.2, 3.5, 4.5, 2.9])
line_style = dict(marker = "8",
markersize = 5,
markerfacecolor="Red",
markeredgecolor="red",
linestyle ="dotted",
linewidth= 2,
)
#label
plt.title("Country GDP",
fontsize = 20,
fontweight = "bold",
color = "Brown")
plt.xlabel("Year",
fontsize = 12,
#family = "arial",
fontweight = "bold",
color = "Purple" )
plt.ylabel("Nu. in Millions",
fontsize = 12,
#family = "arial",
fontweight = "bold",
color = "Purple" )
plt.tick_params(axis ="both",
colors = "purple")
plt.grid()
plt.plot(x, y1,color = "green", **line_style)
plt.plot(x, y2,color = "blue", **line_style)
plt.plot(x, y3, color = "orange",**line_style)
#plt.xticks(x)
plt.show()
In [ ]: