From s.achterop at rug.nl Thu Nov 21 08:48:29 2019 From: s.achterop at rug.nl (s.achterop at rug.nl) Date: Thu, 21 Nov 2019 14:48:29 +0100 Subject: [Matplotlib-devel] Backend for use with Qt/QML Message-ID: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> Hallo List, I need to embed matplotlib in a Qt5/QML application, and found a starting point created by Frederic Collonval. It is a fairly old version, and not working anymore, so I forked it to create an updated version. It can be found on https://github.com/SietseAchterop/matplotlib_qtquick_playground I only updated the backend and the QtQuick version 2 example. But I am stuck in the backend, in backend_qquick5agg.py. In the QtQuick.QQuickPaintedItem function paint in line 118 there is: stringBuffer = self.renderer._renderer.tostring_bgra() Both tostring_xxx functions do not exist anymore. How can I solve this? Is the byteorder problem solved somewhere else? Is this a qt4/qt5 issue? Hopefully someone can point me in a direction. It would be very nice to have a possibility to use matplotlib within QML apps. Thanks in advance, Sietse From tcaswell at gmail.com Fri Nov 22 13:55:48 2019 From: tcaswell at gmail.com (Thomas Caswell) Date: Fri, 22 Nov 2019 13:55:48 -0500 Subject: [Matplotlib-devel] Backend for use with Qt/QML In-Reply-To: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> References: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> Message-ID: Sietse, The methods are only removed from the c++ classes (which is what you are accessing via `_renderer`) which we consider private and will change with no warning (see https://github.com/matplotlib/matplotlib/pull/11735 for the PR where this was done). It looks like there are still public methods with the same name on RendererAgg. I also suggest having a look at how we are doing this in our qt5agg backend ( https://github.com/matplotlib/matplotlib/blob/616d6729368e6f4997bb759b171051a2b9ad882c/lib/matplotlib/backends/backend_qt5agg.py#L61-L75). Is there a reason you can not directly use the QWidget sub-class we provide ( https://github.com/matplotlib/matplotlib/blob/616d6729368e6f4997bb759b171051a2b9ad882c/lib/matplotlib/backends/backend_qt5agg.py#L17 )? Tom On Thu, Nov 21, 2019 at 8:48 AM s.achterop at rug.nl wrote: > Hallo List, > > I need to embed matplotlib in a Qt5/QML application, and found a starting > point created > by Frederic Collonval. > It is a fairly old version, and not working anymore, so I forked it to > create an updated version. > It can be found on > https://github.com/SietseAchterop/matplotlib_qtquick_playground > I only updated the backend and the QtQuick version 2 example. > > But I am stuck in the backend, in backend_qquick5agg.py. > In the QtQuick.QQuickPaintedItem function paint in line 118 there is: > stringBuffer = self.renderer._renderer.tostring_bgra() > > Both tostring_xxx functions do not exist anymore. How can I solve this? > Is the byteorder problem solved somewhere else? Is this a qt4/qt5 issue? > > Hopefully someone can point me in a direction. It would be very nice to > have > a possibility to use matplotlib within QML apps. > > Thanks in advance, > Sietse > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel at python.org > https://mail.python.org/mailman/listinfo/matplotlib-devel > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From s.achterop at rug.nl Sat Nov 23 07:56:02 2019 From: s.achterop at rug.nl (s.achterop at rug.nl) Date: Sat, 23 Nov 2019 13:56:02 +0100 Subject: [Matplotlib-devel] Backend for use with Qt/QML In-Reply-To: References: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> Message-ID: <0e339859-6a5f-b0c6-847e-a8b3a9bdf1de@rug.nl> On 11/22/19 7:55 PM, Thomas Caswell wrote: Thanks Tom for the response. > The methods are only removed from the c++ classes (which is what you are accessing via `_renderer`) which we consider private and will change with no warning (see https://github.com/matplotlib/matplotlib/pull/11735?for the PR where this was done).? It looks like there are still public methods with > the same name on RendererAgg. Yes, but not the tostring_bgra version. And it seems that matplotlib is in rgba byte order, so it needs this conversion when the byteorder is little endian as with a regular PC. Or am I mistaken? My patch, that works on my intel PC, is adding and using the following function def tostring_bgra(self): return np.asarray(self._renderer).take([2, 1, 0, 3], axis=2).tobytes() To RendererAgg. Maybe add this function to RendererAgg? > >? Is there a reason you can not directly use the QWidget sub-class we provide ? Well, this is what the code I forked from did. I think the reason is that to embed in a Qt/QML program and being able to paint directly on the canvas we need to subclass QtQuick.QQuickPaintedItem. See https://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html QML is quite different than traditional Qt. Thanks again, Sietse From antony.lee at institutoptique.fr Sat Nov 23 13:48:36 2019 From: antony.lee at institutoptique.fr (Antony Lee) Date: Sat, 23 Nov 2019 19:48:36 +0100 Subject: [Matplotlib-devel] Backend for use with Qt/QML In-Reply-To: <0e339859-6a5f-b0c6-847e-a8b3a9bdf1de@rug.nl> References: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> <0e339859-6a5f-b0c6-847e-a8b3a9bdf1de@rug.nl> Message-ID: Qt can directly plot from RGBA8888 data (matplotlib's native byte order), per https://doc.qt.io/qt-5/qimage.html#Format-enum. (Yes, the docs mention that it is less optimized but that's just a byteswap, performance-wise I would guess the cost is the same whether it is done on Python's side or Qt's). I guess the place you need to change in your code is https://github.com/SietseAchterop/matplotlib_qtquick_playground/blob/master/backend/backend_qtquick5/backend_qquick5agg.py#L130 (and similar). Antony On Sat, Nov 23, 2019 at 1:56 PM s.achterop at rug.nl wrote: > On 11/22/19 7:55 PM, Thomas Caswell wrote: > > Thanks Tom for the response. > > > The methods are only removed from the c++ classes (which is what you are > accessing via `_renderer`) which we consider private and will change with > no warning (see https://github.com/matplotlib/matplotlib/pull/11735 for > the PR where this was done). It looks like there are still public methods > with > > the same name on RendererAgg. > > Yes, but not the tostring_bgra version. And it seems that matplotlib is in > rgba byte order, so it needs this conversion when > the byteorder is little endian as with a regular PC. Or am I mistaken? > > My patch, that works on my intel PC, is adding and using the following > function > > def tostring_bgra(self): > return np.asarray(self._renderer).take([2, 1, 0, 3], > axis=2).tobytes() > > To RendererAgg. > Maybe add this function to RendererAgg? > > > > > Is there a reason you can not directly use the QWidget sub-class we > provide ? > > Well, this is what the code I forked from did. > I think the reason is that to embed in a Qt/QML program and being able to > paint directly on the canvas we need to subclass QtQuick.QQuickPaintedItem. > See > https://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html > > QML is quite different than traditional Qt. > > Thanks again, > Sietse > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel at python.org > https://mail.python.org/mailman/listinfo/matplotlib-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From isaac.gerg at gergltd.com Sat Nov 23 19:16:30 2019 From: isaac.gerg at gergltd.com (Isaac Gerg) Date: Sat, 23 Nov 2019 19:16:30 -0500 Subject: [Matplotlib-devel] String names for linestyles Message-ID: Is there any reason these string names for linestyles are not inherently in matlotlib? https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/linestyles.html I have to pass the tuple to use the second table of linestyles. Why can't these strings be added to the native list? Thanks, Isaac -------------- next part -------------- An HTML attachment was scrubbed... URL: From elch.rz at ruetz-online.de Sat Nov 23 20:06:19 2019 From: elch.rz at ruetz-online.de (Elan Ernest) Date: Sun, 24 Nov 2019 02:06:19 +0100 Subject: [Matplotlib-devel] String names for linestyles In-Reply-To: References: Message-ID: Linestyles are currently not coherently defined throughout the library. See this issue: https://github.com/matplotlib/matplotlib/issues/11797 Once they are, using more alias names is certainly possible. Currently, there is noone actively working on this, so please feel free to contribute. Am 24.11.2019 um 01:16 schrieb Isaac Gerg: > Is there any reason these string names for linestyles are not > inherently in matlotlib? > > https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/linestyles.html > > I have to pass the tuple to use the second table of linestyles.? Why > can't these strings be added to the native list? > > Thanks, > Isaac > > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel at python.org > https://mail.python.org/mailman/listinfo/matplotlib-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.adrien at gmail.com Sun Nov 24 03:32:03 2019 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Sun, 24 Nov 2019 09:32:03 +0100 Subject: [Matplotlib-devel] String names for linestyles In-Reply-To: References: Message-ID: <6ac05c4d-36f1-aadf-8345-ce76151b433f@gmail.com> Hi Isaac, FWIW, a ?long? time ago, I proposed [#8048](https://github.com/matplotlib/matplotlib/pull/8048), which was actually inspired by the example that you cited. However, I did not manage to pursue the work in order to get significant traction on that very proposal (which is likely to be a tricky one, as it may induce many corner-cases that I did not think of?). Unfortunately, I do not expect to have time resuming on that proposal any time soon. As Elan wrote, please feel free to contribute on this topic :). Best, Adrien Le 24/11/2019 ? 02:06, Elan Ernest a ?crit?: > Linestyles are currently not coherently defined throughout the library. > > See this issue: https://github.com/matplotlib/matplotlib/issues/11797 > > Once they are, using more alias names is certainly possible. Currently, > there is noone actively working on this, so please feel free to contribute. > > > Am 24.11.2019 um 01:16 schrieb Isaac Gerg: >> Is there any reason these string names for linestyles are not >> inherently in matlotlib? >> >> https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/linestyles.html >> >> I have to pass the tuple to use the second table of linestyles.? Why >> can't these strings be added to the native list? >> >> Thanks, >> Isaac >> >> _______________________________________________ >> Matplotlib-devel mailing list >> Matplotlib-devel at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-devel > > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel at python.org > https://mail.python.org/mailman/listinfo/matplotlib-devel > From s.achterop at rug.nl Mon Nov 25 05:37:19 2019 From: s.achterop at rug.nl (s.achterop at rug.nl) Date: Mon, 25 Nov 2019 11:37:19 +0100 Subject: [Matplotlib-devel] Backend for use with Qt/QML In-Reply-To: References: <0e897687-2ac2-333f-6d7d-489083530206@rug.nl> <0e339859-6a5f-b0c6-847e-a8b3a9bdf1de@rug.nl> Message-ID: <1112bde6-5a0b-d0b4-72ea-1a242ec616e3@rug.nl> On 23-11-19 19:48, Antony Lee wrote: > Qt can directly plot from RGBA8888 data (matplotlib's native byte order), per https://doc.qt.io/qt-5/qimage.html#Format-enum. (Yes, the docs mention that it is less optimized but that's just a > byteswap, performance-wise I would guess the cost is the same whether it is done on Python's side or Qt's).? I guess the place you need to change in your code is > https://github.com/SietseAchterop/matplotlib_qtquick_playground/blob/master/backend/backend_qtquick5/backend_qquick5agg.py#L130?(and similar). Thanks Antony. I changed Qt image format to RGBA888 and now do simply stringBuffer = np.asarray(self.renderer._renderer).tobytes() Still am a bit confused about the endian test, but I will find out when I port it to ARM for my android tablet. Thanks, Sietse