10000 Handle axis SI prefix scaling in MatplotlibExporter by ixjlyons · Pull Request #1282 · pyqtgraph/pyqtgraph · GitHub
[go: up one dir, main page]

Skip to content

Handle axis SI prefix scaling in MatplotlibExporter #1282

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

Merged
merged 4 commits into from
Jun 28, 2020

Conversation

ixjlyons
Copy link
Member
@ixjlyons ixjlyons commented Jun 27, 2020

Finally following up #1051

Basic test:

import pyqtgraph as pg
from pyqtgraph.exporters import MatplotlibExporter

plt = pg.plot(x=[0, 1, 2], y=[1e10, 2e10, 3e10])
plt.setLabel('left', 'magnitude')

exp = MatplotlibExporter(plt.plotItem)
exp.export()

pg.mkQApp().exec_()

I ended up sticking with the basic idea of #1051, keeping the axis labels and scaling the data. The alternative I had considered was stripping the prefix from the label and letting matplotlib handle the axis scaling with a multiplier label, but this maintains the pyqtgraph style.

I recommend viewing the diff ignoring whitespace changes. I usually try to make minimal diffs, but removing the unnecessary indentation level seemed worthwhile.

No test because we don't have matplotlib in CI afaik.

Fixes #1050
Fixes #1051

@j9ac9k
Copy link
Member
j9ac9k commented Jun 27, 2020

FYI we can easily add matplotlib to our CI suite if you think this should be tested

@j9ac9k
Copy link
Member
j9ac9k commented Jun 27, 2020

Should probably have a skip if decorator for skipping the test if matplotlib isn't installed

@ixjlyons
Copy link
Member Author

I think it's probably worth adding some test coverage. I'm not sure how much we could/should test in the case of MatplotlibExporter, but I'm up for putting together some basic tests to hit the code paths.

@ixjlyons ixjlyons marked this pull request as draft June 27, 2020 22:25
@j9ac9k
Copy link
Member
j9ac9k commented Jun 27, 2020

Sounds good, I'm not at a computer right now, do you need help with wing matplotlib to the CI pipelines?

@ixjlyons
Copy link
Member Author

Was about to say nah I got it but of course there's a failure...

I think I can figure it out but chime in if you notice something. At the moment I see the naive approach of adding matplotlib to the dependency install line pulled in (py)qt-5 in the Python2-PySide-4.8 job.

@j9ac9k
Copy link
Member
j9ac9k commented Jun 28, 2020

Those Qt4/PySide1/Python2 configs are no joke.

In the "install dependencies" step of the linux/pyside1 pipeline

  pyqt-5.6.0                 |           py27_2         5.3 MB
    pyside-1.2.0               |           py27_0         5.6 MB

I won't be able to help debug this for a few hours; but the problem seems to be that installing matplotlib via conda bundles pyqt5 along with it; which is not at all what we want...

I think we may want to install matplotlib via pip after installing the other dependencies via conda.

@ixjlyons
Copy link
Member Author
ixjlyons commented Jun 28, 2020

Wow, only the Linux Python2-PySide-4.8 job failed despite (py)qt-5 being installed for Windows/MacOS too.

https://dev.azure.com/pyqtgraph/pyqtgraph/_build/results?buildId=996&view=logs&j=fdf8a08f-d10f-57ad-9e84-c0e040fe4fde&t=50eff170-233a-5108-7962-acb3810e8052&l=190

Well, I have to say I was afraid of pretty much exactly this. There's probably a way to write the requirement spec to avoid it, but I'm pretty sure that would ugly up the CI template quite a bit.

@j9ac9k what do you think about only installing it for the pip jobs and letting pytest skip the tests otherwise (skipping alrady implemented)? I guess it would be nice to test this with a variety of Qt versions particularly because it's matplotlib with Qt backends though.

edit: just saw your comment above - that sounds like a reasonable way to do it

@j9ac9k
Copy link
Member
j9ac9k commented Jun 28, 2020

I think we can make this work by installing via pip and specifying which matplotlib dependencies we install. I'm definitely 👎 on writing spec files.

I think either way we should use the skipif decorator and skip those tests if matplotlib is not installed

@ixjlyons
Copy link
Member Author
ixjlyons commented Jun 28, 2020

So just installing with pip in the conda environments seems to work. Their setup.py makes no assumptions about what backend you want, so I think this is a pretty stable solution.

The whole test module is skipped with pytest.importorskip("matplotlib").

Going to move this out of draft but feedback still welcome obviously.

@ixjlyons ixjlyons marked this pull request as ready for review June 28, 2020 01:17
@j9ac9k
Copy link
Member
j9ac9k commented Jun 28, 2020

This might be outside of the scope of this PR, but does matplotlib qt widget offer any kind of dark mode recognition? on macOS, which is running dark mode, this is what the window looks like:

image

pyqtgraph does have some dark mode recognition in the codebase that was introduced as part of #1124

in __main__.py

class App(QtGui.QApplication):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.paletteChanged.connect(self.onPaletteChange)
        self.onPaletteChange(self.palette())

    def onPaletteChange(self, palette):
        self.dark_mode = palette.base().color().name().lower() != "#ffffff"

@j9ac9k
Copy link
Member
j9ac9k commented Jun 28, 2020

Some googling turns up this issue:

matplotlib/matplotlib#8590

A bit more googling, and light icons were merged, but they are slated to be in the 3.3.0 release!

matplotlib/matplotlib#17459

I'm good with hoping this sorts itself out for matplotlib 3.3.0

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

Successfully merging this pull request may close these issues.

Bug: Export to Matplotlib while scientific notation is being used
2 participants
2954
0