Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ak.plot_dist docs example produces an error #3942

Open
ShreyasKhandekar opened this issue Dec 12, 2024 · 0 comments
Open

ak.plot_dist docs example produces an error #3942

ShreyasKhandekar opened this issue Dec 12, 2024 · 0 comments
Labels
bug Something isn't working Doc bug documentation has a bug in it

Comments

@ShreyasKhandekar
Copy link
Contributor

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.

@ShreyasKhandekar ShreyasKhandekar added bug Something isn't working Doc bug documentation has a bug in it labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Doc bug documentation has a bug in it
Projects
None yet
Development

No branches or pull requests

1 participant