pythonmatplotlib

Remove axis ticks and draw upper edge border


I'd like to remove the tick marks from all axes and extend the edge color from the bottom and sides to the top as well. The farthest I have gotten is to draw the ticks as white, which looks bad as they are rendered on top of the edge lines:

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D

mpl.rcParams['ytick.color'] = 'white'
#mpl.rcParams['ytick.left'] = False

sample = np.random.random_integers(low=1,high=5, size=(10,3))

# Create a figure and a 3D Axes
fig = plt.figure(figsize=(5,5))

ax = Axes3D(fig)

#ax.w_xaxis.set_tick_params(color='white')

#ax.axes.tick_params
ax.axes.tick_params(bottom=False, color='blue')
##['size', 'width', 'color', 'tickdir', 'pad', 'labelsize',
##'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On',
##'label1On', 'label2On', 'length', 'direction', 'left', 'bottom',
##'right', 'top', 'labelleft', 'labelbottom',
##'labelright', 'labeltop', 'labelrotation']

colors = np.mean(sample[:, :], axis=1)

ax.scatter(sample[:,0], sample[:,1], sample[:,2],

           marker='o', s=20, c=colors, alpha=1)

ax.tick_params(color='red')

frame1 = plt.gca()
frame1.axes.xaxis.set_ticklabels([])
frame1.axes.yaxis.set_ticklabels([])
frame1.axes.zaxis.set_ticklabels([])
#frame1.axes.yaxis.set_tick_params(color='white')

enter image description here


Solution

  • To answer the first bit of the question, about tick removal, it's probably easiest to just disable the tick lines:

    for line in ax.xaxis.get_ticklines():
        line.set_visible(False)
    for line in ax.yaxis.get_ticklines():
        line.set_visible(False)
    for line in ax.zaxis.get_ticklines():
        line.set_visible(False)
    

    E.g.:

    import numpy as np
    import matplotlib as mpl
    from matplotlib import pyplot as plt
    from matplotlib import animation
    from mpl_toolkits.mplot3d import Axes3D
    
    
    sample = np.random.random_integers(low=1,high=5, size=(10,3))
    
    # Create a figure and a 3D Axes
    fig = plt.figure(figsize=(5,5))
    
    ax = Axes3D(fig)
    
    colors = np.mean(sample[:, :], axis=1)
    
    ax.scatter(sample[:,0], sample[:,1], sample[:,2],
    
               marker='o', s=20, c=colors, alpha=1)
    
    
    ax = plt.gca()
    ax.xaxis.set_ticklabels([])
    ax.yaxis.set_ticklabels([])
    ax.zaxis.set_ticklabels([])
    
    for line in ax.xaxis.get_ticklines():
        line.set_visible(False)
    for line in ax.yaxis.get_ticklines():
        line.set_visible(False)
    for line in ax.zaxis.get_ticklines():
        line.set_visible(False)
    

    enter image description here