简体   繁体   English

在matplotlib中旋转图像?

[英]Rotate an image in matplotlib?

I want to rotate an image generated by plt.imshow() . 我想旋转由plt.imshow()生成的图像。 Is that possible somehow? 有可能吗? I don't want to rotate (with scipy.ndimage.rotate for example) the underlying array I use for plotting, because it always introduces artifacts, and they are affecting what I'm looking at in the image. 我不想旋转(例如,使用scipy.ndimage.rotate )用于绘图的基础数组,因为它始终会引入伪像,并且它们会影响我在图像中查看的内容。 Also would be better for me to have pixels rotated by 45 degrees. 对我来说,将像素旋转45度也更好。

I've found this , where it's suggested to use use the scipy rotate method on the figure. 我找到了这个 ,建议在图中使用scipy rotation方法。 But it doesn't work for me. 但这对我不起作用。 This is the relevant code: 这是相关代码:

im = plt.imshow(np.log2(data+1), origin='lower', interpolation='none', cmap=WhRd,
                        extent=[0, (end-start)*200000, 0, 50*200000])
im_rot = ndimage.rotate(im, 45)

And this is the error, pointing at the second line: 这是错误,指向第二行:

/usr/local/lib/python2.7/dist-packages/scipy/ndimage/interpolation.pyc in rotate(input, angle, axes, reshape, output, order, mode, cval, prefilter)
    631         axes[1] += rank
    632     if axes[0] < 0 or axes[1] < 0 or axes[0] > rank or axes[1] > rank:
--> 633         raise RuntimeError('invalid rotation plane specified')
    634     if axes[0] > axes[1]:
    635         axes = axes[1], axes[0]

RuntimeError: invalid rotation plane specified

Is there any way to achieve what I want? 有什么方法可以实现我想要的吗?

Two suggestions: 两个建议:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM