python matplotlib: way to transpose axes

后端 未结 2 1936
無奈伤痛
無奈伤痛 2020-12-20 14:17

Suppose I have a plotting function that takes an axes argument (or returns one). Is there some low-level method for transposing the whole plot so that the x-axis becomes the

2条回答
  •  不知归路
    2020-12-20 15:01

    Not more than a wrap for tcaswell's answer.

    def swap(*line_list):
        """
        Example
        -------
        line = plot(linspace(0, 2, 10), rand(10))
        swap(line)
        """
        for lines in line_list:
            try:
                iter(lines)
            except:
                lines = [lines]
    
            for line in lines:
                xdata, ydata = line.get_xdata(), line.get_ydata()
                line.set_xdata(ydata)
                line.set_ydata(xdata)
                line.axes.autoscale_view()
    

    An example

    line = plot(linspace(0, 2, 10), rand(10))
    swap(line)
    

提交回复
热议问题