Hi Gene,
Here is a simple function I use to convert mpl colormaps to pyqtgraph form:
import numpy as np
from matplotlib import cm
def colormap(name):
colormap = cm.get_cmap(name)
colormap._init()
# Convert matplotlib colormap from 0-1 to 0-255 for PyQtGraph
lut = (colormap._lut * 255).view(np.ndarray)[:colormap.N]
return lut
You can easily use it to set your colormap in pyqtgraph as follows:
img.setLookupTable(lut)
where img is a PyQtGraph ImageItem. The truncation of the colormap
("[:colormap.N]") keeps only the portion with the colors. mpl has a few
extra entries at the top of the colormap that don't work with pyqtgraph. I
got the function originally from somewhere in these group postings but I
can no longer find it. I added the truncation part. This works well for me
as I display both mpl and pyqtgraph images in a single Qt window.
Hope this helps,
Erik
On Wednesday, September 11, 2019 at 9:09:59 AM UTC-6, Gene Beidl wrote:
>
> I am creating a spectrogram to be displayed as an image and I want to use
> the magma colormap from Matplotlib.
>
> It's shown here:
> https://matplotlib.org/users/colormaps.html
>
> And some 'magma' mapped spectrograms are here:
> https://librosa.github.io/librosa_gallery/auto_examples/plot_hprss.html
>
> Is there a way to use Matplotlib colormaps with an image in pyqtgraph?
>
> 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/9f5c8628-1ddb-4fb7-b231-47c898dea06e%40googlegroups.com.