Data Visualisation with Matplotlib

I used the following code for the task : In the previous step, you created a figure with four subplots using pyplot . Now try to create the same figure using the object-oriented API! Here are the specifications again:

  • First plot:
    • Plot the tangent of x . The line should be a blue dashed line.
    • Give it the title “Tan(x)”.
  • Second plot:
    • Plot the exponential of x . The line should be dark green and have a width of 5.
    • Give it the title “Exp(x)”.
  • Both plots:
    • Label the x -axis “x-values” and the y -axis “y-values”.
    • Change the x axis limits to -4 to 4.
    • Plots should not overlap.

Hint: your two subplots can be accessed using the indexes [0] and [1] .

my code:

TASK — Create a figure with two subplots

x = np.arange(-np.pi, np.pi, 0.1)

------- Your code here:

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8,5))

axes[0].set_title(‘Tan(x)’)
axes[0].plot(x, np.tan(x),‘b–’)
axes[0].set_xlabel(“x-values”)
axes[0].set_ylabel(“y-values”)
axes[0].set_xlim(-4,4)
axes[0].set_ylim(-40,80)

axes[1].set_title(‘Exp(x)’)
axes[1].plot(x,np.exp(x),color=‘darkgreen’,linewidth=5)
axes[1].set_xlabel(“x-values”)
axes[1].set_ylabel(“y-values”)
axes[1].set_xlim(-4,4)

But there is still an error. Can someone help me please

Hey Krishna!

Thanks for reaching out! Any chance you can send the Share URL (the Share icon can be found in the bottom left corner) so we can look into it for you?

Best,
Lorraine