1

I'm sorry if this is expected behavior, but I wanted to understand what was going on here better. So if I try to draw a circle with plt.Circle and projection='3d'

import matplotlib.pyplot as plt

f2 = plt.figure()
ax1 = f2.add_subplot(1,1,1,projection='3d')

x = plt.Circle([1,1],radius=10)
ax1.add_artist(x)

ax1.set_xlim(0,100)
ax1.set_ylim(0,100)
ax1.set_zlim(0,100)

plt.show()

then I get the following bizarre outcome:

enter image description here

although it all works as expected if I just remove the projection='3d'. I would appreciate any context as to why this weird result happens, I guess I don't totally understand why projection='3d' would mangle things so much.

user49404
  • 732
  • 6
  • 22

1 Answers1

3

You need somewhere a projection from 2d to 3d to accommodate your circular artist. One way is to create a circle patch and map it to 3d as shown in here, which I have adapted to answer your question. You can choose zdir='x' to be zdir='y' or zdir='z' as per your need.

import matplotlib.pyplot as plt
from matplotlib.patches import Circle, PathPatch
from mpl_toolkits.mplot3d import Axes3D 
import mpl_toolkits.mplot3d.art3d as art3d

f2 = plt.figure()
ax1 = f2.add_subplot(1,1,1,projection='3d')

circle = Circle((1, 1), 10, edgecolor='red', facecolor=None, fill=False)
ax1.add_patch(circle)
art3d.pathpatch_2d_to_3d(circle, z=0, zdir='x')

ax1.set_xlim3d(-20, 20)
ax1.set_ylim3d(-20, 20)
ax1.set_zlim3d(-20, 20)

enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71