How do I convert (or scale) axis values and redefine the tick frequency in matplotlib?

后端 未结 1 2002
天命终不由人
天命终不由人 2020-12-08 05:20

I am displaying a jpg image (I rotate this by 90 degrees, if this is relevant) and of course the axes display the pixel coordinates. I would like to convert the axis so that

相关标签:
1条回答
  • 2020-12-08 05:41

    It looks like you're dealing with the matplotlib.pyplot interface, which means that you'll be able to bypass most of the dealing with artists, axes, and the like. You can control the values and labels of the tick marks by using the matplotlib.pyplot.xticks command, as follows:

    tick_locs = [list of locations where you want your tick marks placed]
    tick_lbls = [list of corresponding labels for each of the tick marks]
    plt.xticks(tick_locs, tick_lbls)
    

    For your particular example, you'll have to compute what the tick marks are relative to the units (i.e. pixels) of your original plot (since you're using imshow) - you said you know how to do this, though.

    I haven't dealt with images much, but you may be able to use a different plotting method (e.g. pcolor) that allows you to supply x and y information. That may give you a few more options for specifying the units of your image.

    For tutorials, you would do well to look through the matplotlib gallery - find something you like, and read the code that produced it. One of the guys in our office recently bought a book on Python visualization - that may be worthwhile looking at.

    The way that I generally think of all the various pieces is as follows:

    • A Figure is a container for all the Axes
    • An Axes is the space where what you draw (i.e. your plot) actually shows up
    • An Axis is the actual x and y axes
    • Artists? That's too deep in the interface for me: I've never had to worry about those yet, even though I rarely use the pyplot module in production plots.
    0 讨论(0)
提交回复
热议问题