How to add axes labels to plot?
jiunyen-ching opened this issue · 2 comments
jiunyen-ching commented
jiunyen-ching commented
Temporary workaround: Adding plt.xlabel
and plt.ylabel
after plot_3d( ) works for x-axis and y-axis but not for z-axis as AttributeError: module 'matplotlib.pyplot' has no attribute 'zlabel'
.
Minimal example code:
from skspatial.objects import Plane
from skspatial.objects import Points
from skspatial.plotting import plot_3d
points = Points([[0, 0, 0], [1, 3, 5], [-5, 6, 3], [3, 6, 7], [-2, 6, 7]])
plane = Plane.best_fit(points)
plot_3d(
points.plotter(c='k', s=50, depthshade=True),
plane.plotter(alpha=0.2, lims_x=(-5, 5), lims_y=(-5, 5)),
)
plt.xlabel('x')
plt.ylabel('y')
jiunyen-ching commented
Solved: in ../site-packages/skspatial/plotting.py
, add
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
A full edit of the function to accept optional argument:
def plot_3d(*plotters: Callable, set_label=False) -> Tuple:
"""Plot multiple spatial objects in 3D."""
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
if set_label:
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
for plotter in plotters:
plotter(ax)
return fig, ax