[Matplotlib-users] Matplotlib 3D: Remove axis ticks & draw upper edge border?
Mike Kaufman
mckauf at gmail.com
Sun Mar 4 11:23:15 EST 2018
What I did as a workaround this is to modify the plot limits:
#########################################################################
#
#########################################################################
def equalize_plotlimits_3d(ax):
xl = ax.get_xlim()
yl = ax.get_ylim()
zl = ax.get_zlim()
xr = xl[1] - xl[0]
yr = yl[1] - yl[0]
zr = zl[1] - zl[0]
xave = (xl[1] + xl[0])/2
yave = (yl[1] + yl[0])/2
zave = (zl[1] + zl[0])/2
maxr = max([xr,yr,zr])
ax.set_xlim(xave-maxr/2, xave+maxr/2)
ax.set_ylim(yave-maxr/2, yave+maxr/2)
ax.set_zlim(zave-maxr/2, zave+maxr/2)
xl = ax.get_xlim()
yl = ax.get_ylim()
zl = ax.get_zlim()
return [xl,yl,zl]
#########################################################################
#
#########################################################################
def pan(axis, shift, ax=None, dodraw=True):
if not ax: ax = gca()
which = dict(x=0,y=1,z=2)
setter = [ax.set_xlim, ax.set_ylim, ax.set_zlim]
getter = [ax.get_xlim, ax.get_ylim, ax.get_zlim]
lim = getter[which[axis]]()
lim[0] += shift
lim[1] += shift
setter[which[axis]](lim)
if dodraw:
draw()
def xpan(*args, **kwargs):
pan('x', *args, **kwargs)
def ypan(*args, **kwargs):
pan('y', *args, **kwargs)
def zpan(*args, **kwargs):
pan('z', *args, **kwargs)
#########################################################################
#
#########################################################################
def zoom(scale, ax=None, dodraw=True):
if not ax: ax = gca()
xl = ax.get_xlim()
yl = ax.get_ylim()
zl = ax.get_zlim()
xr = xl[1] - xl[0]
yr = yl[1] - yl[0]
zr = zl[1] - zl[0]
xave = (xl[1] + xl[0])/2
yave = (yl[1] + yl[0])/2
zave = (zl[1] + zl[0])/2
maxr = max([xr,yr,zr])
ax.set_xlim(xave-maxr/2/scale, xave+maxr/2/scale)
ax.set_ylim(yave-maxr/2/scale, yave+maxr/2/scale)
ax.set_zlim(zave-maxr/2/scale, zave+maxr/2/scale)
xl = ax.get_xlim()
yl = ax.get_ylim()
zl = ax.get_zlim()
if dodraw:
draw()
On 3/1/18 11:44 AM, Benjamin Root wrote:
> Sorry, those features are just not possible with the current design. The
> code assumes that all rotations are done from the center. And the tick
> marks aren't handled the same way they are in 2D graphs, unfortunately.
> Also, the code has just three backing panels. It is possible to make one
> or more of them invisible, but you can't add more panels. In fact, you
> wouldn't want other panels to appear because it is assumed that these
> panels will always appear behind any other artists. Any other panels
> would run the risk of being composed incorrectly with the contents of
> the plot, creating "Escher effects" -- visual paradoxes. Nothing is
> stopping you, though, from putting in your own panel from a Poly3D or
> Patch3D object. In fact, you can just create a Patch artist and put it
> through the 2d to 3d converter function in mplot3d.art3d.
>
> I would consider the current state of tick control to be buggy, and I
> agree that effort should be spent fixing it. Having the ability to
> specify an arbitrary point of rotation is an interesting feature and I
> wouldn't be opposed to a merge request adding that feature.
>
>
> On Thu, Mar 1, 2018 at 8:30 AM, fosa <jayme.c.fosa at gmail.com
> <mailto:jayme.c.fosa at gmail.com>> wrote:
>
> Hello,
>
> I've been trying to no avail to use the settings that usually work with
> matplotlib 2D. I'd like to remove the 3D graph ticks, and extend the
> darkened color edge to the upper sides as well. As a bonus if
> someone knows
> how to control the axis of rotation for a 3d animation, to effectively
> control the centering, that would be a great help as well.
>
> Here is a self contained code block that I've been hacking away at
> with a
> dull knife:
>
> 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')
> ax.spines['left'].set_color('green')
>
> frame1 = plt.gca()
> frame1.axes.xaxis.set_visible(False)
> #frame1.axes.xaxis.axes.set_xticks([])
> frame1.axes.xaxis.set_ticklabels([])
> frame1.axes.yaxis.set_ticklabels([])
> frame1.axes.zaxis.set_ticklabels([])
> #frame1.axes.yaxis.set_tick_params(color='white')
>
> And the image it generates:
> <http://matplotlib.1069221.n5.nabble.com/file/t5138/3dSO.png
> <http://matplotlib.1069221.n5.nabble.com/file/t5138/3dSO.png>>
>
> Setting #frame1.axes.xaxis.axes.set_xticks([]) causes all the grid
> lines to
> disappear, instead of just the ticks themselves.
> Is it required to go into whatever is drawing/rendering and adjust the
> length of the grid line? T_T
>
>
>
>
>
> --
> Sent from:
> http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html
> <http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
> https://mail.python.org/mailman/listinfo/matplotlib-users
> <https://mail.python.org/mailman/listinfo/matplotlib-users>
>
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
More information about the Matplotlib-users
mailing list