How do I change the color of the axes of a matplotlib 3D plot?

前端 未结 2 1369
无人共我
无人共我 2020-12-20 06:38

I have set

import matplotlib as mpl
AXES_COLOR = \'#333333\'
mpl.rc(\'axes\', edgecolor=AXES_COLOR, labelcolor=AXES_COLOR, grid=True)
mpl.rc(\'xtick\', color         


        
相关标签:
2条回答
  • 2020-12-20 07:04

    Instead of changing axis3d.py try this: ax.w_xaxis.line.set_color("red")

    0 讨论(0)
  • 2020-12-20 07:25

    Turns out it's impossible since these values are hard-coded. This archived email from the matplotlib-users mailing list helped me. Here's the relevant part:

    Unfortunately, you have stumbled upon one of the ugliness of the mplot3d implementation. I am hoping to have more control available for the next release. But right now, there is no way to turn off the axes spines (because they aren't implemented as spines). If you really want to dig into the source code, you could change the color argument to the Line2D call in the init3d() method in matplotlib/lib/mpl_toolkits/axis3d.py

    Although this answer was addressing another concern, it sent me to the direction of axis3d.py. I found it in /usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d. I made a backup of the original axis3d.py and I moved axis3d.pyc away.

    Since the code is pretty short and fairly well written it didn't take long to locate the two lines I had to change.

    • To change the color of the edges of the individual axes, I modified the self.line=... in __init__: just replace color=(0, 0, 0, 1) by color=(1, 0, 0, 1) for a horribly flashy red. Components of the tuple are red, green, blue, alpha, all floats from 0 to 1.
    • To change the color of the grid, I modified the draw method. I replaced the color self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines)) by something of my choosing.

    And that's it, it just works. Not the most convenient, but it's not more work than editing a rc configuration file.

    I did not recreate a .pyc file. It does not recreate itself because I do not run my python code as root. I don't mind the extra milliseconds that python needs to recompile the .py each time.

    0 讨论(0)
提交回复
热议问题