Luke,
Thanks for providing a complete example. Your code works correctly.
However, I would like to set a png image (it's a map) as the background of
a plot.
When I run combine your code with Karl's to load a png from file, I get the
exception below:
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
plt = pg.plot([1,5,2,4,3], pen='r')
img = QtGui.QImage('c:\Temp\solar-terminator-fig.png')
img = img.convertToFormat(QtGui.QImage.Format_ARGB32_Premultiplied)
imgArray = pg.imageToArray(img, copy=True)
imgitem = pg.ImageItem(imgArray)
plt.addItem(imgitem)
imgitem.setZValue(-100) # make sure image is behind other data
imgitem.setRect(pg.QtCore.QRectF(0, 0, 4, 5))
imgitem.setLevels([0, 10]) # make image appear a bit darker
Traceback (most recent call last):
File "C:\apps\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line
790, in rescaleData
raise Exception('Weave is disabled; falling back to slower version.')
Exception: Weave is disabled; falling back to slower version.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"C:\apps\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 309, in paint
self.render()
File
"C:\apps\Anaconda3\lib\site-packages\pyqtgraph\graphicsItems\ImageItem.py",
line 301, in render
argb, alpha = fn.makeARGB(image.transpose((1, 0, 2)[:image.ndim]),
lut=lut, levels=self.levels)
File "C:\apps\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line
942, in makeARGB
data = rescaleData(data, scale/(maxVal-minVal), minVal, dtype=int)
File "C:\apps\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line
828, in rescaleData
d2 *= scale
TypeError: Cannot cast ufunc multiply output from dtype('float64') to
dtype('uint8') with casting rule 'same_kind'
Traceback (most recent call last):
File "C:\apps\Anaconda3\lib\site-packages\pyqtgraph\functions.py", line
790, in rescaleData
raise Exception('Weave is disabled; falling back to slower version.')
On Monday, December 2, 2013 at 7:29:37 AM UTC-5, Luke Campagnola wrote:
>
> On Mon, Dec 2, 2013 at 2:15 AM, Simon Hafner <[email protected]
> <javascript:>> wrote:
>
>> Hello
>>
>> I'm looking for a way to use an image as background to plot data onto.
>> The data consists of lines. With matplotlib, I achieved this effect using
>> `imshow`. Is there a similar method in pyqtgraph? I considered stacking an
>> ImageView onto a graph, but I haven't found how to stack widgets yet.
>>
>
> You can add an ImageItem directly to a PlotItem or PlotWidget, then use
> ImageItem.scale, .translate, or .setRect to change the boundaries of the
> image relative to the plot data:
>
> import pyqtgraph as pg
>
> plt = pg.plot([1,5,2,4,3], pen='r')
>
> img_data = pg.np.random.normal(size=(100,100))
> img = pg.ImageItem(img_data)
> plt.addItem(img)
> img.setZValue(-100) # make sure image is behind other data
> img.setRect(pg.QtCore.QRectF(0, 0, 4, 5))
> img.setLevels([0, 10]) # make image appear a bit darker
>
> Karl's example is similar to this, and also shows how to load image data
> from a file.
> Alternately, you could keep the ImageView and add a PlotDataItem to its
> internal ViewBox.
>
>
> Luke
>
--
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/4b3e13cb-2f8c-417f-9697-00708d2a5f50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.