Tick ​​tags for matplotlib 3D graphics

I am trying to determine how to set / fix the position of tick marks for matplotlib 3D plot. Tick ​​marks do not match ticks. The problem seems to be especially noticeable when many shortcut shortcuts are required.

I modified the example ( http://matplotlib.org/examples/mplot3d/polys3d_demo.html ) from the matplotlib documentation to illustrate my question.

from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib.colors import colorConverter import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(10,10)) ax = fig.gca(projection='3d') cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6) xs = np.arange(0, 10, 0.4) verts = [] zs = np.arange(50) for z in zs: ys = np.ones(len(xs))*z ys[0], ys[-1] = 0, 0 verts.append(list(zip(xs, ys))) poly = PolyCollection(verts,facecolor='c') poly.set_alpha(0.7) ax.add_collection3d(poly, zs=zs, zdir='y') ax.set_xlabel('X') ax.set_xlim3d(0, 10) ax.set_ylabel('Y') ax.set_ylim3d(-1, len(zs)) ax.set_yticks(np.arange(len(zs))) labels = {} for l_c in zs: labels[l_c] = 'This Looks Bad' ax.set_yticklabels(labels,rotation=-15) ax.set_zlabel('Z') ax.set_zlim3d(0, ys.max()) plt.show() 

enter image description here

So the question is this: how can I bind tag labels to tick positions?

+6
source share
2 answers

Using these alignments, I get much better placements:

 ax.set_yticklabels(labels,rotation=-15, verticalalignment='baseline', horizontalalignment='left') 

I changed the example with lower tick marks so that you can see the placement:

enter image description here

+10
source

They are aligned, but with a horizontal position centered on the mark. Due to the 3D view, this makes them a little lower where you expect them to be. The effect does not depend on the number of ticks, but on the width.

In particular, adjusting the alignment will help. Try adding:

 ax.set_yticklabels(labels,rotation=-15, va='center', ha='left') 

Play a little with different settings to see what you prefer, I think you're after ha = 'left'.

Reducing the indentation, the distance from the check mark can also help.

enter image description here

+5
source

All Articles