Common origin in matplotlib figures

I am plotting a 3D scatter using matplotlib, but I cannot get the figure to have a common origin for all three axes. How can i do this?

My code (so far), I have not implemented any definitions for axis specifications, because I am very new to Python:

  from mpl_toolkits.mplot3d.axes3d import Axes3D
  import matplotlib.pyplot as plt


  # imports specific to the plots in this example
  import numpy as np
  from matplotlib import cm
  from mpl_toolkits.mplot3d.axes3d import get_test_data

  def randrange(n, vmin, vmax):
  return (vmax-vmin)*np.random.rand(n) + vmin

  # Same as wide as it is tall.
  fig = plt.figure(figsize=plt.figaspect(1.0))


  ax = fig.add_subplot(111, projection='3d')

  n = 512

  xs = np.random.randint(0, 10, size=n)
  ys = np.random.randint(0, 10, size=n)
  zs = np.random.randint(0, 10, size=n)
  colors = np.random.randint(0, 10, size=n)
  scat = ax.scatter(xs, ys, zs, c=colors, marker='o')

  ax.set_xlabel('X Label')
  ax.set_ylabel('Y Label')
  ax.set_zlabel('Z Label')


  fig.colorbar(scat, shrink=0.5, aspect=10)

  plt.show()
+4
source share
2 answers

Perhaps you mean something like the following (from Mathematica):

Mathematica

Currently, I can only build some lines centered on (0,0,0):

xline=((min(data[:,0]),max(data[:,0])),(0,0),(0,0))
ax.plot(xline[0],xline[1],xline[2],'grey')
yline=((0,0),(min(data[:,1]),max(data[:,1])),(0,0))
ax.plot(yline[0],yline[1],yline[2],'grey')
zline=((0,0),(0,0),(min(data[:,2]),max(data[:,2])))
ax.plot(zline[0],zline[1],zline[2],'grey')

This is the result:

Matplotlib

0
source

If you put a line

ax.view_init(30,220)

front

plt.show()

you should get what you want for the xy plane. I don’t know how to transfer this plane to z = 0.

0
source

All Articles