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

Axes Numerical Ticks in Exponential Form not Formatting Properly in Log Scale #90

Closed
ndawe opened this issue Apr 29, 2022 · 5 comments
Closed

Comments

@ndawe
Copy link

ndawe commented Apr 29, 2022

Great library! Just hit the problem below when creating a log-log plot that seems to be due to how the tick labels are constructed.

Here's a minimal example to reproduce the issue:

import plotext as plt

plt.xscale("log")
plt.yscale("log")
plt.plot(
    [3.66070161e-08, 4.70771327e-07, 6.13046022e-07, 9.78958201e-01,
    9.97156618e-01, 1.00000000e+00],
    [5.60983465e-12, 5.07770834e-11, 6.79463166e-11, 5.34865283e-01,
    8.23871623e-01, 9.99762833e-01]
)
plt.show()

This causes:

  File "...site-packages/plotext/_monitor.py", line 1153, in <listcomp>
    labels = [el[: el.index('.') + d + 2] for el in labels]
ValueError: substring not found

The value of labels at that point is:

['1e-11', '4.2e-10', '3.157e-08', '2.36823e-06', '0.00017765659999999998', '0.013327207709999999', '0.9997628329999999']

and there is no decimal point in the first label. distinguishing_digit() might also be returning too many digits in this case.

@piccolomo
Copy link
Owner

Great Issue report, thanks a lot. I will have a look at it. Kind of resting a bit after latest upload (it was a big work).

@ndawe
Copy link
Author

ndawe commented Apr 29, 2022

Thanks @piccolomo !

@nelbren
Copy link
Contributor

nelbren commented May 19, 2022

Quick fix:

  1. Replace the line:
    labels = [str(ut.round(el, d + 1)) for el in ticks]
  1. For this new line:
    labels = [f"{ut.round(el, d + 1):f}" for el in ticks]

Regards! 🙂

@piccolomo
Copy link
Owner

cool, i will come back to this in following weeks. i slowly creating next minor version. if you think it works feel free to go ahead with a pull request. for now thanks for the issue and solution.
Savy

nelbren added a commit to nelbren/plotext that referenced this issue May 19, 2022
…omo#90"

**Implementing the quick fix:**
1)  Replace the line: 

```
    labels = [str(ut.round(el, d + 1)) for el in ticks]
```
2) For this new line:

```
    labels = [f"{ut.round(el, d + 1):f}" for el in ticks]
```

Regards! 🙂
piccolomo added a commit that referenced this issue May 20, 2022
Fix the "Issue when formatting tick labels for log scale plots #90"
@piccolomo
Copy link
Owner

Hello @ndawe and @nelbren ,

I have solved the issue in the new version 5.1, available only on GitHub for now, using:

pip install git+https://github.com/piccolomo/plotext

Any feedback or double test is appreciated.
Thanks and all the best,
Savino

@piccolomo piccolomo changed the title Issue when formatting tick labels for log scale plots Axes Numerical Ticks in Exponential Form not Formatting Properly in Log Scale Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants