How come no data appears on my line chart?

89 views Asked by At

I am assigned to update my line chart using the object oriented approach:

  1. Change the line color to green.

  2. Change the marker to a diamond.

  3. Change the line width to 2 points.

  4. Add a legend for the city of Boston.

  5. Add a title and axes labels.

  6. Add a y-axis limit.

  7. Add grid lines.

For the matlab version the following lines of code are used and they end up producing a line graph with all the necessary info.

# Create the plot.
plt.plot(x_axis, y_axis, marker="*", color="blue", linewidth=2, label='Boston')
# Create labels for the x and y axes.
plt.xlabel("Date")
plt.ylabel("Fare($)")
# Set the y limit between 0 and 45.
plt.ylim(0, 45)
# Create a title.
plt.title("PyBer Fare by Month")
# Add a grid.
plt.grid()
# Add the legend.
plt.legend()

Line Chart

This was my attempt at using the object oriented version based on the numbered steps provided above:

x_axis = ["Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]

y_axis = [10.02, 23.24, 39.20, 35.42, 32.34, 27.04, 43.82, 10.56, 11.85, 27.90, 20.71, 20.09]

# Create the plot.
ax.plot(x_axis,y_axis)

ax.plot(x_axis, y_axis, marker="D", color="green", linewidth=2, label='line')

# Create labels for the x and y axes.
ax.set_xlabel("Date")
ax.set_ylabel("Fare ($)")

# Set the y limit between 0 and 45.
ax.set_ylim(0,45)

# Create a title.
ax.set_title("PyBer Fare by Month")

# Add a grid.
ax.grid()
ax.legend('Boston')

The correct output is supposed to look like this:

Plot 2

0

There are 0 answers