ajhynes7/scikit-spatial

How to add axes labels to plot?

jiunyen-ching opened this issue · 2 comments

Hi, I was wondering if there is a way to add labels to the axes to better orient myself to the plot? The desired outcome would be something like this (highlighted by red circles)

image
Thank you for your time!

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')

Output:
image

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