Search code examples
pythonmatplotlibfigure

matplotlib: change axis orientation


I used matplotlib to plot a 3d figure

def showlab(dic, title): 
    global driehoeken
    fig = plt.figure() 
    ax = fig.add_subplot(111, projection = '3d') 
    lijst = np.array(driehoeken)
    lijst = np.around(lijst, 2)
    poly3d = [[lijst[i, j*3:j*3+3]for j in range(3)]for i in range(lijst.shape[0])]
    ax.add_collection3d(Poly3DCollection(poly3d, linewidth = 1)) 
    ax.set_xlim(0, 100) 
    ax.set_xlabel('l') 
    ax.set_ylim(-150, 150) 
    ax.set_ylabel('a')
    ax.set_zlim(-150, 150)
    ax.set_zlabel('b') 
    plt.title(title)
    plt.show()

This plot a figure with the 'b' axis pointed upwards. But I want to have the 'l' axis pointed upwards, but keep the right hand rule. Is there a easy way to do this?


Solution

  • You can reverse the axis just setting the limits in the proper order:

    ax.set_xlib(100, 0)
    

    There's a similar question in StackOverflow: Reverse Y-axis in PyPlot