Issue
I want to visualise matplotlibs colormaps (similar to http://matplotlib.org/examples/color/colormaps_reference.html) and use it as QPixmaps in PyQt widgets. The idea is to create the plots in matplotlib without actually showing it (or saving it to a file) and convert it to a QPixmap. The solution offered here (Python - matplotlib - PyQT: Copy image to clipboard) doesn't seem to work, maybe because I don't want to show the matplotlib plot.
Solution
I have tried the following and that works:
def testColourMap(cmap):
sp = SubplotParams(left=0., bottom=0., right=1., top=1.)
fig = Figure((2.5,.2), subplotpars = sp)
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
ax.imshow(gradient, aspect=10, cmap=cmap)
ax.set_axis_off()
canvas.draw()
size = canvas.size()
width, height = size.width(), size.height()
im = QImage(canvas.buffer_rgba(), width, height, QImage.Format_ARGB32)
return QPixmap(im)
Answered By - Michael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.