Home > Back-end >  I'm having trouble plotting a 2D graph alongside a 3D graph using mat plot lib
I'm having trouble plotting a 2D graph alongside a 3D graph using mat plot lib

Time:12-24

I have a code block that produces a 3d graph

ax = plt.axes(projection = '3d')
ax.plot3D(outputs_real, outputs_imaginary, inputs)
ax.set_xlabel('Real Component')
ax.set_ylabel('Imaginary Component')
ax.set_zlabel('Inputs')
plt.show()

enter image description here and a second code block that makes a 2d graph using 2 of the above's axes.

ax2 = plt.plot(outputs_real, outputs_imaginary)
ax2.set_xlabel('Real Component')
ax2.set_ylabel('Imaginary Component')

But for some reason when I try to plot the second one I'll get this error

AttributeError: 'list' object has no attribute 'set_xlabel'

and the second graph will map onto the first like this: enter image description here

I want the two graphs to be separate

Details:

  1. This is being done in a Jupyter notebook
  2. outputs_real, outputs_imaginary, and inputs are all lists

CodePudding user response:

From matplotlib 3D

2D

CodePudding user response:

One option is to create a new figure. After you have called the first plt.show() create a new figure and ax with

plt.figure(2)
ax2 = plt.axes()

You can also plot the two figures simultaneously if you want, by not calling the first plt.show() and only calling plt.show() after creating both of the figures.

  • Related