Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide axes and gridlines in Matplotlib (python) [duplicate]

I would like to be able to hide the axes and gridlines on a 3D matplotlib graph. I want to do this because when zooming in and out the image gets pretty nasty. I'm not sure what code to include here but this is what I use to create the graph.

fig = plt.figure() ax = fig.gca(projection='3d') ax.view_init(30, -90) ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_zlabel("Z") plt.xlim(0,pL) plt.ylim(0,pW) ax.set_aspect("equal")  plt.show() 

This is an example of the plot that I am looking at:
This is an example of the plot that I am looking at

like image 816
Alex Santelle Avatar asked Jul 17 '17 15:07

Alex Santelle


People also ask

How do I get rid of gridlines in MatPlotLib?

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

What does %Matplotlib do in Python?

Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy. As such, it offers a viable open source alternative to MATLAB. Developers can also use matplotlib's APIs (Application Programming Interfaces) to embed plots in GUI applications.

How do I hide axis in PLT?

To hide the axis, we can use the command matplotlib. pyplot. axis('off') . It hides both the X-axis and Y-axis in the figure.


Video Answer


2 Answers

# Hide grid lines ax.grid(False)  # Hide axes ticks ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) 

Note, you need matplotlib>=1.2 for set_zticks() to work.

like image 56
azalea Avatar answered Sep 23 '22 20:09

azalea


Turn the axes off with:

plt.axis('off') 

And gridlines with:

plt.grid(b=None) 
like image 40
Johnnyh101 Avatar answered Sep 23 '22 20:09

Johnnyh101