Skip to content

ak.plot_dist docs example produces an error #3942

Closed

Description

@ShreyasKhandekar

Describe the bug
The example for plot_dist at https://bears-r-us.github.io/arkouda/autoapi/arkouda/plotting/index.html#arkouda.plotting.plot_dist does not work and causes a bug as follows:

To Reproduce

>>> b, h = ak.histogram(ak.arange(10), 3)
>>> ak.plot_dist(b, h.to_ndarray())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lus/scratch/khandeka/arkouda/arkouda/plotting.py", line 50, in plot_dist
    plt.plot(b, h, marker=".", linestyle="solid")
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/pyplot.py", line 3794, in plot
    return gca().plot(
           ^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_axes.py", line 1779, in plot
    lines = [*self._get_lines(self, *args, data=data, **kwargs)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 296, in __call__
    yield from self._plot_args(
               ^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 481, in _plot_args
    axes.xaxis.update_units(x)
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axis.py", line 1750, in update_units
    converter = munits.registry.get_converter(data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/units.py", line 183, in get_converter
    first = cbook._safe_first_finite(x)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/cbook.py", line 1781, in _safe_first_finite
    for val in obj:
               ^^^
  File "/lus/scratch/khandeka/arkouda/arkouda/pdarrayclass.py", line 887, in __iter__
    raise NotImplementedError(
NotImplementedError: pdarray does not support iteration. To force data transfer from server, use to_ndarray

If we also convert b to an ndarray as the doc should, we still get a different error:

>>> ak.plot_dist(b.to_ndarray(), h.to_ndarray())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lus/scratch/khandeka/arkouda/arkouda/plotting.py", line 50, in plot_dist
    plt.plot(b, h, marker=".", linestyle="solid")
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/pyplot.py", line 3794, in plot
    return gca().plot(
           ^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_axes.py", line 1779, in plot
    lines = [*self._get_lines(self, *args, data=data, **kwargs)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 296, in __call__
    yield from self._plot_args(
               ^^^^^^^^^^^^^^^^
  File "/lus/scratch/khandeka/anaconda3/envs/arkouda-dev/lib/python3.12/site-packages/matplotlib/axes/_base.py", line 486, in _plot_args
    raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (3,) and (4,)

Expected behavior
A plot of the distribution and cumulative distribution of the histrogram data

Is this a Blocking Issue
Not blocking

  • Are there any known work-arounds? yes
  • If a known work around exists, please provide a code block demonstrating it.
    We can preprend b with a 0 to make the dimensions equal to h:
b = ak.concatenate([ak.array([0]), b])

Which then makes the dimensions of b and h equal and generates the plot.

Also we don't need to do plt.show() to show the plot, which is the opposite of what the docs claim.

Activity

  1. added
    bug
    Doc bug
    on Dec 12, 2024
  2. self-assigned this
    on Sep 5, 2025
  3. added 8 commits that reference this issue on Sep 5, 2025
    58dd491
    1e5efbe
    5bfd8fe
    e0cba04
    c948d77
    3df8204
    dbff33e
    7bb62e8
  4. added a commit that references this issue on Sep 24, 2025
    d387322
  5. added a commit that references this issue on Sep 25, 2025
    69a9fec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Doc bugbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions