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

Feature: Boxplot support #2542

Open
noonchen opened this issue Nov 30, 2022 · 5 comments · May be fixed by #2562
Open

Feature: Boxplot support #2542

noonchen opened this issue Nov 30, 2022 · 5 comments · May be fixed by #2562

Comments

@noonchen
Copy link
Contributor

Greetings,

I am trying to rewrite matplotlib code in pyqtgraph, but it seems boxplot (matplotlib api) is not presented in the latest release, and surprisingly I cannot find any example in google or StackOverFlow.

Is it possible to add it in the roadmap?

Thanks!

@j9ac9k
Copy link
Member

j9ac9k commented Dec 14, 2022

Hi @noonchen

We're not opposed to adding box-plot support, but given that those kinds of plots don't typically undergo rapid updating, we're probably not going to get much interest from maintainers on implementing it (I do not speak for other maintainers besides myself so I could be mistaken here).

We do have an example that shows how to do your own boxplot which may be of help if you want to roll out your own thing; the code isn't too bad.

Example: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/examples/customGraphicsItem.py

Result:

image

If you all do roll out your own thing, and want to contribute it to the library, we would certainly be receptive to that!

@noonchen
Copy link
Contributor Author

Hi @j9ac9k,

Thanks for the example! , I looked into the code and I think I can implement one on my own. If it looks good I'll create a pr.

@noonchen
Copy link
Contributor Author

noonchen commented Dec 20, 2022

Hi @j9ac9k ,

I am working on the boxplot feature, it is almost finished, but I have encountered some difficulties in drawing outlier points, hope you can give me some advice.

The outlier points are scatter points drew at both ends of boxplot, it would be expensive to embed a ScatterPlotItem so that I tried to copy some logics from scatter plot, but these scatter points are distorted, the expected output should look like scatter plot with pxMode=False.

image

Code can be found here.

@pijyoi
Copy link
Contributor

pijyoi commented Dec 25, 2022

I was able to draw your outlier points in device coordinates by moving the relevant code out of QPicture and into the paint() method itself. It seems that there are some limitations as to what can be drawn into a QPicture.

There are some other things to handle, which would be computing the boundingRect to include the outliers.

    def paint(self, p, *args):
        if self.picture is None:
            self.generatePicture()
        p.drawPicture(0, 0, self.picture)

        if not self.opts["outlier"]:
            return

        # outlier related style
        if isinstance(self.opts["symbol"], QtGui.QPainterPath):
            symbol = self.opts["symbol"]
        else:
            symbol = QtGui.QPainterPath()
            symbol.addEllipse(QRectF(-0.5, -0.5, 1, 1))
        symbolPen = pg.mkPen(self.opts["symbolPen"])
        symbolSize = 5 if self.opts["symbolSize"] is None else self.opts["symbolSize"]
        symbolBrush = pg.mkBrush(self.opts["symbolBrush"])

        p.setPen(symbolPen)
        p.setBrush(symbolBrush)
        for pos, outliers in self.outlierData.items():
            for o in outliers:
                x, y = (pos, o)
                pt = self.mapToScene(x, y)
                tr = QtGui.QTransform.fromTranslate(pt.x(), pt.y()).scale(symbolSize, symbolSize)
                p.setTransform(tr)
                p.drawPath(symbol)

@noonchen
Copy link
Contributor Author

@pijyoi Thank you so much! This problem has bothered me for so long, your solution works perfectly.

@noonchen noonchen linked a pull request Dec 26, 2022 that will close this issue
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 a pull request may close this issue.

3 participants