I am using matplotlib for doing this
from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [6,3,6,9,12,24] y = [3,5,78,12,23,56] ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z') plt.show()
Now this builds a graph that is horizontal in the 3d space. How do I make the graph vertical so that it faces the user?
What I want to do is build multiple such vertical graphs that are separated by some distance and are facing the user.
3D plotting in Matplotlib starts by enabling the utility toolkit. We can enable this toolkit by importing the mplot3d library, which comes with your standard Matplotlib installation via pip. Just be sure that your Matplotlib version is over 1.0. Now that our axes are created we can start plotting in 3D.
Using subplots() method, create a figure and a set of subplots. Plot [1, 2, 3, 4, 5] data points on the left Y-axis scales. Using twinx() method, create a twin of Axes with a shared X-axis but independent Y-axis, ax2. Plot [11, 12, 31, 41, 15] data points on the right Y-axis scale, with blue color.
Generally 3D scatter plot is created by using ax. scatter3D() the function of the matplotlib library which accepts a data sets of X, Y and Z to create the plot while the rest of the attributes of the function are the same as that of two dimensional scatter plot.
bp's answer might work fine, but there's a much simpler way.
Your current graph is 'flat' on the z-axis, which is why it's horizontal. You want it to be vertical, which means that you want it to be 'flat' on the y-axis. This involves the tiniest modification to your code:
from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [6,3,6,9,12,24] y = [3,5,78,12,23,56] # put 0s on the y-axis, and put the y axis on the z-axis ax.plot(xs=x, ys=[0]*len(x), zs=y, zdir='z', label='ys=0, zdir=z') plt.show()
Then you can easily have multiple such graphs by using different values for the ys parameter (for example, ys=[2]*len(x)
instead would put the graph slightly behind).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With