How to plot an image with non-linear y-axis with Matplotlib using imshow?

前端 未结 4 818
猫巷女王i
猫巷女王i 2020-12-09 19:58

How can I plot an 2D array as an image with Matplotlib having the y scale relative to the power of two of the y value?

For instance the first row of my array will ha

4条回答
  •  醉话见心
    2020-12-09 20:38

    If you want both to be able to zoom and save memory, you could do the drawing "by hand". Matplotlib allows you to draw rectangles (they would be your "rectangular pixels"):

    from matplotlib import patches
    axes = subplot(111)
    axes.add_patch(patches.Rectangle((0.2, 0.2), 0.5, 0.5))
    

    Note that the extents of the axes are not set by add_patch(), but you can set them yourself to the values you want (axes.set_xlim,…).

    PS: I looks to me like thrope's response (matplotlib.image.NonUniformImage) can actually do what you want, in a simpler way that the "manual" method described here!

提交回复
热议问题