Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide the axes in matplotlib 3d?

How can I make a 3D plot without showing the axes?

When plotting a 3d plot, Matplotlib not only draws the x, y, and z axes, it draws light gray grids on the x-y, y-z, and x-z planes. I would like to draw a "free-floating" 3D plot, with none of these elements.

Stuff I've tried:

# Doesn't work; this hides the plot, not the axes my_3d_axes.set_visible(False)  # Doesn't do anything. Also, there's no get_zaxis() function. my_3d_axes.get_xaxis().set_visible(False) my_3d_axes.get_yaxis().set_visible(False) 
like image 910
SuperElectric Avatar asked Sep 07 '11 15:09

SuperElectric


People also ask

How do I get rid of grid lines in Matplotlib?

MatPlotLib with Python Load an image from a file. Convert the image from one color space to another. To remove grid lines, use ax. grid(False).

How do I hide a spine in Matplotlib?

To turn the spines off - you can access them via the ax. spines dictionary. Using their keys, top , bottom , left , and right , you can select each one, and using the set_visible() function, turn them off.

Are 3D graphs possible in Matplotlib?

Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit.


1 Answers

Ben Root provided a patch that fixes this for 1.0.1. It can be found as an attachment to the last email of this thread. To quote Ben:

Ok, looks like the hiding of the 3d axes was a feature added after the v1.0 release (but before I started working on mplot3d). This patch should enable the basic feature without interfering with existing functions. To hide the axes, you would have to set the private member "_axis3don" to False, like so:

ax = plt.gca(projection='3d') ax._axis3don = False

If you do it this way, then you will get what you want now, and your code will still be compatible with mplot3d when you upgrade (although the preferred method would be to call set_axis_on() or set_axis_off()).

I hope that helps!

Ben Root

like image 50
SuperElectric Avatar answered Oct 08 '22 00:10

SuperElectric