Hey, I've tried replicating the suggestions but cant seem to get anything 
to appear, I wrote the script below and ran it from the windows command 
prompt using Python. I'm using numpy 1.14, pyqt 5.9 and pyqtgraph 0.10. 
When I just use the code suggested by Samuel Palato nothing gets displayed 
either. I've also tried running this in a jupyter notebook but to no avail.

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore


class IndexedAxis(pg.AxisItem):
    """
    Axis where pixels are mapped using a numpy array
    """
    def __init__(self, orientation, mapping=None, **kw):
        super(IndexedAxis, self).__init__(orientation, **kw)
        self.mapping = mapping
        self.fmt = "{:.02f}"

    def tickStrings(self, values, scale, spacing):
        if self.mapping is None:
            return super(IndexedAxis, self).tickStrings(values, scale, 
spacing)
        # count values smaller than 0
        labels = []
        idx = np.array(values, dtype=np.int)-1
        left_pad = np.count_nonzero(idx < 0)
        right_pad = np.count_nonzero(idx >= self.mapping.size)
        idx = np.compress(np.logical_and(idx>=0, idx< self.mapping.size),
                          idx)
        labels.extend([""]*left_pad)
        labels.extend([self.fmt.format(v) for v in self.mapping[idx]])
        labels.extend([""]*right_pad)
        return labels

app = QtGui.QApplication([])
mw = QtGui.QMainWindow
view = pg.GraphicsLayoutWidget()
w1 = view.addPlot()

x_values = np.linspace(-100, 100)
mapped_axis = IndexedAxis('bottom', mapping=x_values)
plot_item = pg.PlotItem(axisItems={'bottom': mapped_axis})
image_item =pg.ImageItem()
plot_item.addItem(image_item)

w1.addItem(plot_item)





On Tuesday, April 19, 2016 at 6:50:05 PM UTC+1, Samuel Palato wrote:
>
> Hi,
>
> I managed to do something similar.
>
> My data has x and y axes with almost constant spacing, so I'm ok with even 
> sized pixels on display. However, the x and y axes display custom values, 
> looked up from the corresponding arrays. This is a bit closer to the 
> behavior of `matplotlib.imshow` with the `extent` keyword.
>
> The trick is to subclass `AxisItem` in order to display custom tick 
> labels. See: 
> https://bitbucket.org/snippets/spalato/X6nL4/indexed-axis#file-IndexedAxis.py
> You then need to create the axis items and pass them to the PlotItem your 
> ImageItem is going to reside in:
> x_values = np.linspace(-100, 100, n=51)
> mapped_axis = IndexedAxis('bottom', mapping=x_values)
> plot_item = pg.PlotItem(axisItems={'bottom': mapped_axis})
> image_item =pg.ImageItem()
> plot_item.addItem(image_item)
> Or something similar.
> To update the axis values, you need to update the axis' `mapping` 
> attribute to the new values.
>
> So far, this works, but I get an extra set of axes in the top right 
> corner. (which brought me here...)
>
> If constant pixels are unacceptable, you could try creating a display 
> image using nearest interpolation, and plotting the resulting image using 
> the technique described above.
>
> Hope this helps,
> Samuel Palato
>
>
> On Thursday, 17 March 2016 09:37:17 UTC-4, Nicola Creati wrote:
>>
>> Hello,
>> I'm trying to move from Matplotlib to PyQtGraph but I need something 
>> equivalent to the Matplotlib pcolormesh/pcolor command that accepts X, Y 
>> and C as input. *X* and *Y *specify the (*x*, *y*) coordinates of the 
>> colored quadrilaterals and C is the array of values. Can I get the same 
>> with PyQtGraph, please?
>> Thanks.
>>
>> Nicola
>>
>

-- 
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/4c60ccb6-3836-4879-9910-ade94f749111%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to