Adjusting gridlines on a 3D Matplotlib figure

前端 未结 4 2200
感动是毒
感动是毒 2021-02-15 03:05

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.

4条回答
  •  粉色の甜心
    2021-02-15 04:08

    Unfortunately this doesn't seem to be exposed. Looking over the source, the key internal variable is call _AXINFO which we can override by careful subclassing.

    enter image description here

    Add this code after your figure is created, and style it with the dict custom_AXINFO:

    from mpl_toolkits.mplot3d import Axes3D
    import mpl_toolkits.mplot3d.axis3d as axis3d
    
    # New axis settings
    custom_AXINFO = {
        'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2),
              'color': (0.00, 0.00, 0.25, .75)},
        'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2),
              'color': (0.20, 0.90, 0.90, 0.25)},
        'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1),
              'color': (0.925, 0.125, 0.90, 0.25)},}
    
    class custom_XAxis(axis3d.Axis):
        _AXINFO = custom_AXINFO
    
    class custom_YAxis(axis3d.Axis):
        _AXINFO = custom_AXINFO
    
    class custom_ZAxis(axis3d.Axis):
        _AXINFO = custom_AXINFO
    
    class custom_Axes3D(Axes3D):
        def _init_axis(self):
            '''Init 3D axes; overrides creation of regular X/Y axes'''
            self.w_xaxis = custom_XAxis('x', self.xy_viewLim.intervalx,
                                        self.xy_dataLim.intervalx, self)
            self.xaxis = self.w_xaxis
            self.w_yaxis = custom_YAxis('y', self.xy_viewLim.intervaly,
                                self.xy_dataLim.intervaly, self)
            self.yaxis = self.w_yaxis
            self.w_zaxis = custom_ZAxis('z', self.zz_viewLim.intervalx,
                                self.zz_dataLim.intervalx, self)
            self.zaxis = self.w_zaxis
    
            for ax in self.xaxis, self.yaxis, self.zaxis:
                ax.init3d()
    
    # The rest of your code below, note the call to our new custom_Axes3D
    
    points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose()
    fig = plt.figure(figsize = (10,10)) 
    ax = custom_Axes3D(fig)
    

    This is monkey-patching at it's worst, and should not be relied upon to work for later versions.

    Fixing the facecolors was easier than the grid lines, as this requires an override of one of the __init__ methods, though it could be done with more work.

    It does not seem difficult to expose this to the end user, and as such I can imagine that this may be fixed in later versions.

提交回复
热议问题