If I have a 3D matplotlib plot (Axes3D
object), how do I change the color of the tick marks? I figured out how to change the color of the axis line, the tick labels, and the axis label. The obvious solution, use ax.tick_params(axis='x', colors='red')
, only changes the tick labels not the tick marks themselves.
Here is code that tries to change all the axes to red and gets everything but the tick marks:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))
ax.w_xaxis.line.set_color('red')
ax.w_yaxis.line.set_color('red')
ax.w_zaxis.line.set_color('red')
ax.w_zaxis.line.set_color('red')
ax.xaxis.label.set_color('red')
ax.yaxis.label.set_color('red')
ax.zaxis.label.set_color('red')
ax.tick_params(axis='x', colors='red') # only affects
ax.tick_params(axis='y', colors='red') # tick labels
ax.tick_params(axis='z', colors='red') # not tick marks
fig.show()
To set the color for X-axis and Y-axis, we can use the set_color() method (Set both the edgecolor and the facecolor). To set the ticks color, use tick_params method for axes. Used arguments are axis ='x' (or y or both) and color = 'red' (or green or yellow or ...etc.)
Ticks are easier to identify once they are done feeding because their body becomes engorged. The scutum remains the same size, but the body will become larger and change color once feeding is complete. The colors range from brownish red to pale gray or greenish grey.
As mentioned in manual page about tick_params(axis='both', **kwargs)
you get a bug:
While this function is currently implemented, the core part of the Axes3D object may ignore some of these settings. Future releases will fix this. Priority will be given to those who file bugs.
To override this problem use inner _axinfo
dictionary as in this example:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))
ax.xaxis._axinfo['tick']['color']='r'
ax.yaxis._axinfo['tick']['color']='r'
ax.zaxis._axinfo['tick']['color']='r'
plt.show()
A straightforward way to achieve the expected result is as follows:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import rcParams
from matplotlib import pyplot as plt
rcParams['xtick.color'] = 'red'
rcParams['ytick.color'] = 'red'
rcParams['axes.labelcolor'] = 'red'
rcParams['axes.edgecolor'] = 'red'
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter((0, 0, 1), (0, 1, 0), (1, 0, 0))
plt.show()
The output display is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With