question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nelbrencommented, 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! 🙂

1reaction
piccolomocommented, Apr 29, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matplotlib log scale tick label number formatting - Stack Overflow
To change the formatter to the default for linear axes ( ScalarFormatter ) use e.g. What if I wanted to change the numbers...
Read more >
Creating Exponential Notation Axis Labels - Peltier Tech
The first step is to hide the built in axis labels. Double click on one axis, select the Patterns tab, and select None...
Read more >
1.11 FAQ-122 How do I format the axis tick labels? - OriginLab
Change Numeric Tick Label Display. Double click on the axis tick labels or select Format: Axes: X/Y/Z Axis... menu go to Tick Labels...
Read more >
Format axes Tick Labels in log scale - MATLAB Answers
Dear all, an annoying issue when plotting on log scales, is apparently not being able to control the format of axis tick labels....
Read more >
Syntax: PROC SGPANEL COLAXIS Statement - SAS Help Center
specifies how to scale and format the values for the major tick marks for logarithmic axes. LOGVTYPE=EXPANDED | EXPONENT. specifies the scale ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found