Examination 2

Insert your corresponding code in the space provided.

DS100-1
3Q1920

This exam consists of 4 items which is all coding in data visualization using python.

Note: Items are jumbled and I don't have the questions.

Item 1
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

x_values = [10, 20, 30]
y_values = [20, 40, 10]
ax.plot(x_values, y_values,':b', label='line1-dotted')

x2_values = [10, 20, 30]
y2_values = [40,10,30]
ax.plot(x2_values, y2_values, '--r', label='line2-dashed')

leg = ax.legend()
plt.xlabel("x-axis")
plt.ylabel("y-axis")

plt.show()


Item 2
import matplotlib.pyplot as plt
import numpy as np

x = np.random.randint(100, size=50)
y = np.random.randint(100, size=50)

plt.scatter(x,y, color='g')

plt.xlabel("x-axis")
plt.ylabel("y-axis")

plt.show()


Item 3
import matplotlib.pyplot as plt
import numpy as np

ax = plt.axes()

x = np.arange(6)
y = 5 * x

plt.title("y = 5x line graph")
plt.xlabel("x-axis")
plt.ylabel("y-axis")
ax.plot(x, y, c="g")
plt.show()


Item 4
import matplotlib.pyplot as plt

x = ['Civil', 'Chemical', 'Mechanical', 'Electronics', 'Electrical', 'Industrial']

enrollees = [22.2, 17.6, 8.8, 8, 7.7, 6.7]

xaxis = np.arange(len(x))

plt.bar(x_pos, enrollees, color='r')
plt.ylabel("Enrollees (in 1000)")

plt.xticks(x_pos, x, rotation=45)
plt.show()