Skip to content
Advertisement

How to change spines linewidth in 3D plot?

When you have a 2D plot in matplolib you can change the line width of spines (the containing box) as follows:

fig, ax = plt.subplots()
ax.plot([1,2,3])
spines = ax.spines
[i.set_linewidth(5) for i in spines.values()]

Figure with thick spines: notice super thick box lines

However this same methodology does not work for 3D plots. How could I change the axes line thickness for a 3D plot?

Advertisement

Answer

You can do this using the following code. I adapted the idea of accessing the axes in 3D from this answer. If you want to change the thickness of all the grid lines as well, refer to this answer by ImportanceOfBeingErnest

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

for axis in [ax.w_xaxis, ax.w_yaxis, ax.w_zaxis]:
    axis.line.set_linewidth(5)

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement