So here’s a short snippet of code that works for me to get a plot with a
transparent background:
from PySide2.QtWidgets import QApplication, QDialog, QVBoxLayout
from PySide2.QtGui import QBrush
from PySide2.QtCore import Qt
import pyqtgraph as pg
if __name__ == "__main__":
app=QApplication()
dialog=QDialog()
dialog.setStyleSheet('background-color:#050’)
layout=QVBoxLayout(dialog)
dialog.setLayout(layout)
vals=list(range(100))
plotWidget=pg.PlotWidget(dialog)
plotWidget.setBackgroundBrush(QBrush(Qt.transparent,Qt.NoBrush))
plotWidget.plot(vals)
layout.addWidget(plotWidget)
dialog.show()
app.exec_()
---
Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell: 907-328-9145
> On Apr 12, 2020, at 7:59 AM, Daniele Dolci <[email protected]> wrote:
>
> I understand, I appreciated the help you gave so far. Is it possible it has
> to do with some css?
>
> Thanks!
>
> Il giorno dom 12 apr 2020 alle ore 17:51 Israel Brewster
> <[email protected] <mailto:[email protected]>> ha scritto:
> I’ll have to find some time to go back over my code and see what I’m missing
> then, because it’s working for me. Dunno off the top of my head. Sorry!
> ---
> Israel Brewster
> Software Engineer
> Alaska Volcano Observatory
> Geophysical Institute - UAF
> 2156 Koyukuk Drive
> Fairbanks AK 99775-7320
> Work: 907-474-5172
> cell: 907-328-9145
>
>> On Apr 12, 2020, at 7:22 AM, Daniele Dolci <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> Hi!
>>
>> I gave it a try but still same result. I uninstalled everything with
>>
>> sudo pip3 uninstall pyqtgraph
>>
>>
>> and made sure that under dist-packages there was nothing left. Then I tried
>> to download it from source forge but with no much success, finally, as is
>> read here https://github.com/pyqtgraph/pyqtgraph
>> <https://github.com/pyqtgraph/pyqtgraph> , I used the command:
>>
>> pip install git <>+ <>https <>: <>//github.com/pyqtgraph/pyqtgraph@develop <>
>>
>> or, actually,
>>
>> sudo pip3 install git <>+ <>https <>:
>> <>//github.com/pyqtgraph/pyqtgraph@develop <>
>> Any other idea of what I could try?
>>
>> Cheers,
>>
>>
>> Il giorno sabato 11 aprile 2020 21:42:11 UTC+2, Daniele Dolci ha scritto:
>> Alright, tomorrow I will try download the development version then and give
>> it a try.
>>
>> I will let you know how it goes, thanks!
>>
>> Cheers,
>>
>> Il giorno sabato 11 aprile 2020 20:09:40 UTC+2, Israel Brewster ha scritto:
>> Nope, that would be the latest *release* version, which would be 0.10. I’m
>> using the latest *development* version that you can get from source forge.
>> So yeah, that *could* be why my code isn’t working for you (though I don’t
>> guarantee it).
>>
>> There have been a lot of changes between the last release and the current
>> development (like compatibility with PySide2, which is why I use the
>> development). I keep wondering when they will make a new release, but it
>> hasn’t happened yet.
>> ---
>> Israel Brewster
>> Software Engineer
>> Alaska Volcano Observatory
>> Geophysical Institute - UAF
>> 2156 Koyukuk Drive
>> Fairbanks AK 99775-7320
>> Work: 907-474-5172
>> cell: 907-328-9145
>>
>>> On Apr 11, 2020, at 10:06 AM, Daniele Dolci <[email protected] <>> wrote:
>>>
>>> I would assume I am on the latest version, I installed it today. One
>>> difference perhaps might be the operative system? I am using raspbian OS.
>>>
>>> To install it I used
>>>
>>> sudo apt install python3-pyqtgraph
>>>
>>> So I assume it gets the latest one, or not?
>>>
>>> Il giorno sabato 11 aprile 2020 19:58:36 UTC+2, Israel Brewster ha scritto:
>>> One thought that just occurred to me: I’m using the latest development
>>> version of pyqtgraph. Are you by any chance on the release version? That
>>> could be the difference, theoretically, if so.
>>>
>>> ---
>>> Israel Brewster
>>> Software Engineer
>>> Alaska Volcano Observatory
>>> Geophysical Institute - UAF
>>> 2156 Koyukuk Drive
>>> Fairbanks AK 99775-7320
>>> Work: 907-474-5172
>>> cell: 907-328-9145
>>>
>>>> On Apr 11, 2020, at 9:51 AM, Daniele Dolci <[email protected] <>> wrote:
>>>>
>>>> So I tried this:
>>>>
>>>> x = [x for x in range(1000)]
>>>> y = [x for x in range(1000)]
>>>> plotWidget = pg.PlotWidget(title="Ph")
>>>> plotWidget.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.transparent,
>>>> QtCore.Qt.NoBrush))
>>>> self._tab_layout.addWidget(plotWidget, 0, 0)
>>>> t = plotWidget.plot(x, y)
>>>>
>>>> But the background is still white. I removed all the viewBox stuff and the
>>>> set colors. I mean, this is very weird. If the plot accepts colors for pen
>>>> and background in the format of RGBa, why wouldn't the transperency do the
>>>> trick?
>>>>
>>>> I have also tried using just plotItem, without the widget, but I wasn't
>>>> able to add it to the layout so I couldn't really finish the test.
>>>>
>>>> Thanks for your time man, I appreciate!
>>>> Cheers,
>>>>
>>>> Il giorno sabato 11 aprile 2020 19:42:31 UTC+2, Israel Brewster ha scritto:
>>>> No, I mis-spoke with that. I took another look at my code, and realized
>>>> that I’m not doing *anything* with the view box. So try just doing the
>>>> setBackgroudBrush on the plotWidget, but *don’t* set the background color
>>>> on the view box at all. If that doesn’t work, then I’m probably missing
>>>> something somewhere else in my code that does it…
>>>>
>>>> ---
>>>> Israel Brewster
>>>> Software Engineer
>>>> Alaska Volcano Observatory
>>>> Geophysical Institute - UAF
>>>> 2156 Koyukuk Drive
>>>> Fairbanks AK 99775-7320
>>>> Work: 907-474-5172
>>>> cell: 907-328-9145
>>>>
>>>>> On Apr 11, 2020, at 8:37 AM, Daniele Dolci <[email protected] <>>
>>>>> wrote:
>>>>>
>>>>> Thanks for the fast reply!
>>>>>
>>>>> I tried to add that line but didn't work. I then tried to apply it to the
>>>>> plot item and to the view box, but on both I get the error:
>>>>>
>>>>> plotWidget.getViewBox().setBackgroundBrush(QtGui.QBrush(QtCore.Qt.transparent,
>>>>> QtCore.Qt.NoBrush))
>>>>> AttributeError: 'ViewBox' object has no attribute 'setBackgroundBrush'
>>>>>
>>>>> Maybe I misunderstood what you meant by doing the same for the ViewBox?
>>>>>
>>>>> Thanks again!
>>>>>
>>>>>
>>>>> Il giorno sabato 11 aprile 2020 18:20:06 UTC+2, Israel Brewster ha
>>>>> scritto:
>>>>> Try:
>>>>>
>>>>> plotWidget.setBackgroundBrush(QBrush(Qt.transparent, Qt.NoBrush))
>>>>>
>>>>> There may be some other code needed as well, but that’s at least part of
>>>>> it. you *may* need to do the same for the view box. So you had the right
>>>>> idea, but perhaps not quite right?
>>>>> ---
>>>>> Israel Brewster
>>>>> Software Engineer
>>>>> Alaska Volcano Observatory
>>>>> Geophysical Institute - UAF
>>>>> 2156 Koyukuk Drive
>>>>> Fairbanks AK 99775-7320
>>>>> Work: 907-474-5172
>>>>> cell: 907-328-9145
>>>>>
>>>>>> On Apr 11, 2020, at 8:11 AM, Daniele Dolci <[email protected] <>>
>>>>>> wrote:
>>>>>>
>>>>>> Hi!
>>>>>>
>>>>>> I have a main widget with a layout and a gradient as background. I want
>>>>>> to add a series of plots with transperent background (basically I would
>>>>>> like to only draw the foreground). I am having hardtimes making the
>>>>>> background of the plot transperent. I tried lot of things, with this
>>>>>> code I was expecting that I would be making all transparent, but it is
>>>>>> actually white:
>>>>>>
>>>>>> x = [x for x in range(1000)]
>>>>>> y = [x for x in range(1000)]
>>>>>> plotWidget = pg.PlotWidget(title="Ph")
>>>>>> plotWidget.setBackground((0, 0, 0, 0))
>>>>>> plotWidget.getViewBox().setBackgroundColor((0, 0, 0, 0))
>>>>>> self._tab_layout.addWidget(plotWidget, 0, 0)
>>>>>> pen = pg.mkPen(color=(255, 0, 0))
>>>>>> t = plotWidget.plot(x, y, pen=pen)
>>>>>> t.getViewBox().setBackgroundColor((0, 0, 0, 0))
>>>>>>
>>>>>> So it looks like this, and I would:
>>>>>>
>>>>>> <plot1.jpg>
>>>>>>
>>>>>>
>>>>>> And I would like to have it drawn on this background instead:
>>>>>> <plot2.jpg>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Any idea how to fix this?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "pyqtgraph" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>>> an email to [email protected] <>.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/pyqtgraph/2e9b649e-dc5e-4a92-ad3f-b6b9cfb6226d%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/pyqtgraph/2e9b649e-dc5e-4a92-ad3f-b6b9cfb6226d%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>>>> <plot1.jpg><plot2.jpg>
>>>>>
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups
>>>>> "pyqtgraph" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>>> email to [email protected] <>.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/pyqtgraph/3c60ca81-99f3-4c4c-9a4e-7cd22d7f9335%40googlegroups.com
>>>>>
>>>>> <https://groups.google.com/d/msgid/pyqtgraph/3c60ca81-99f3-4c4c-9a4e-7cd22d7f9335%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "pyqtgraph" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>> email to [email protected] <>.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/pyqtgraph/4c71a8d2-5d8c-41a7-a3d2-e5a9dc106117%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/pyqtgraph/4c71a8d2-5d8c-41a7-a3d2-e5a9dc106117%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "pyqtgraph" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected] <>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pyqtgraph/4d6a1fdc-0df4-435e-a362-1e5b8e0328fb%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/pyqtgraph/4d6a1fdc-0df4-435e-a362-1e5b8e0328fb%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyqtgraph" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected]
>> <mailto:[email protected]>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pyqtgraph/770c9bdc-6fd4-46bc-a1fd-64e212790413%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/pyqtgraph/770c9bdc-6fd4-46bc-a1fd-64e212790413%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyqtgraph" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyqtgraph/2FCF8E91-6628-4A0B-83B3-0B24F22CB62D%40alaska.edu
>
> <https://groups.google.com/d/msgid/pyqtgraph/2FCF8E91-6628-4A0B-83B3-0B24F22CB62D%40alaska.edu?utm_medium=email&utm_source=footer>.
>
>
> --
> Daniele Dolci
> Technical Director & Python Developer
> Vetralla, Italy
> M: +39 331 200 5242
> E: [email protected] <mailto:[email protected]>
> W: https://www.linkedin.com/in/danieledolci95
> <https://www.linkedin.com/in/danieledolci95>
> Skype: dolci.daniele
> Portfolio (YouTube): https://youtu.be/IMZdW4ikjok
> <https://youtu.be/IMZdW4ikjok>
> =======================================
> Insanity: doing the same thing over and over again and expecting different
> results.
> - Albert Einstein -
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyqtgraph" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyqtgraph/CAF_JKbCxJK1NUrcrJnJ0m8eLfAHGt11POh5knCPmLwL3--d%3D3A%40mail.gmail.com
>
> <https://groups.google.com/d/msgid/pyqtgraph/CAF_JKbCxJK1NUrcrJnJ0m8eLfAHGt11POh5knCPmLwL3--d%3D3A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/002D5626-0ADA-409F-B5D1-886B97086DA3%40alaska.edu.