Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting gridlines on a 3D Matplotlib figure

I'm getting ready for a presentation and I have some example figures of 3D matplotlib figures. However, the gridlines are too light to see on the projected images. example 3D image

I tried using the grid-method that works for 2D figures:

points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose()
fig = plt.figure(figsize = (10,10))
ax = fig.add_subplot(111, projection='3d') 
ax.scatter(points[:,0], points[:,1], points[:,2])
ax.view_init(elev=0., azim=0)
ax.set_ylim([0, 60])
ax.set_zlim([0, 60])
ax.set_xlim([0, 60])
ax.set_zlabel('Cytokine')
ax.set_ylabel('Parameter')
ax.grid(linewidth=20)

But that doesn't seem to work for 3D figures. Any suggestions?

like image 475
JudoWill Avatar asked Jul 29 '13 13:07

JudoWill


People also ask

How do I set the grid size in MatPlotLib?

MatPlotLib with Python Make x and y margins 0. To set X-grids, we can pass input ticks points. To lay out the grid lines in current line style, use grid(True) method. To display the figure, use show() method.

How do I show grid lines in MatPlotLib?

By default, Matplotlib does not display gridlines on plots. However, you can use the matplotlib. pyplot. grid() function to easily display and customize gridlines on a plot.

Can MatPlotLib Pyplot be used to display 3D plots?

Matplotlib can also handle 3D plots by allowing the use of a Z axis. We've already created a 2D scatter plot above, but in this example we'll create a 3D scatter plot: Watch video here.

Are 3D graphs possible in MatPlotLib?

We can create 3D plots in Python thanks to the mplot3d toolkit in the matplotlib library. Matplotlib was introduced with only 2D plots in mind. However, as of the 1.0 release, 3D utilities were developed on top of 2D, so 3D implementations of data are available today.


1 Answers

If to lighten the background of grid, can use setting the pane color more light (eg:white) using Axes3DSubplot object as below.

ax.w_xaxis.pane.set_color('w');
ax.w_yaxis.pane.set_color('w');
ax.w_zaxis.pane.set_color('w');

Or else to highlight the grid lines further, can updated grid color parameter of plot.

plt.rcParams['grid.color'] = "black"
like image 161
Gimhani Avatar answered Oct 26 '22 10:10

Gimhani