Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib 3D: Remove axis ticks & draw upper edge border?

It seems like some of the methods that work for matplotlib 2D might not be working for matplotlib 3D. I'm not sure.

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 being able to draw the ticks as white, which looks bad as they are rendered on top of the edge lines.

Below is a big chunk of self-contained code that results in the following image. Any help is much appreciated!

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

like image 495
Fosa Avatar asked Feb 28 '18 10:02

Fosa


People also ask

How do I get rid of ticks in Matplotlib?

Matplotlib removes both labels and ticks by using xticks([]) and yticks([]) By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis.

How do I remove axis labels in Matplotlib?

The plot in Matplotlib by default shows the ticks and ticklabels of two axes as shown in the example figure. It has different methods to hide the axis text, like xaxis. set_visible(False) , xaxis. set_ticks([]) and xaxis.

What does ticks do in Matplotlib?

Ticks are the values used to show specific points on the coordinate axis. It can be a number or a string. Whenever we plot a graph, the axes adjust and take the default ticks. Matplotlib's default ticks are generally sufficient in common situations but are in no way optimal for every plot.


1 Answers

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

like image 87
Saulius Lukauskas Avatar answered Sep 20 '22 16:09

Saulius Lukauskas