Use log modulus transform for y axis log scaling#1476
Use log modulus transform for y axis log scaling#1476j9ac9k merged 4 commits intopyqtgraph:masterfrom
Conversation
|
Closing/Re-Opening to trigger CI run on our fancy new CI system. |
|
Closing and re-opening (again) as I updated the CI one more time... |
|
Hi @Hanwant sorry it's taken me a while to follow up on this. I've had my head in migrating CI platforms, which is more or less finished. Thanks for the PR, I approve of the change, but I'm not feeling great about the May I suggest we use what I've done in my projects if something like this: if np.issubdtype(y, np.floating):
epsilon = np.finfo(y.dtype).eps
else:
epsilon = 1
y = np.sign(y) * np.log10(np.abs(y) + epsilon)What do you think? |
|
Nice plot, thanks for sharing!
Didn't think about that, but I think that's fine. To take log of negative numbers, the library will have to do something, and it's not going to fit all use-cases; ideally the end user handles negative numbers on their own so the library doesn't have to, but I think sign * log10(abs(y) + epsilon) is completely fine. I would advocate for using the |
|
Cool, sounds good. Have made the change and assumed the docstring was intended for setLogMode? |
|
/home/runner/work/pyqtgraph/pyqtgraph/doc/source/../../pyqtgraph/graphicsItems/PlotDataItem.py:docstring of pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem.setLogMode:3: WARNING: Definition list ends without a blank line; unexpected unindent. This is the error the CI reported, I think it wants an empty line before/after |
|
if it's not obvious to you, I'll hop on your branch and tinker with it locally as I have the doc build environment already setup |
|
the macOS CI failure is an intermittent failure I haven't figured out a good way to deal with yet, it's unrelated to this PR. |
|
Btw along with a '\n' I changed the indent from a tab to spaces, not sure which helped |
|
oh, given it was a docstring, I was going to suggest, just adding extra new-lines """
To enable log scaling for y<0 and y>0, the following formula is used:
scaled = sign(y) * log10(abs(y) + eps)
where eps is the smallest unit of y.dtype.
This allows for handling of 0. values, scaling of large values,
""" |
|
Oh right, that's clearer, updated again |
|
Thanks for the patience, this was my first PR to an open source project. |
|
Congratulations on your first PR! FWIW this is the first open source project I've been a maintainer of (that wasn't just some personal project). If you see some other area that pyqtgraph could use some improvement in, and know how to to make the fix or want input, please reach out. Thanks, merging. |

Changes the log transform of y variable from:
y = np.log10(y)to:
y = np.sign(y) * np.log10(np.abs(y)+1)This allows log scaling of negative as well as positive values. '0' values in the original array remain 0, at the expense that the transformed values are now approximately log10(y) instead of exactly log10(y).
This is helpful for my use cases, thought it might be for others too.