python twin.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python twin.py相关的知识,希望对你有一定的参考价值。

from matplotlib import pyplot as plt


def twin(show="xy", ax=None):
    """
    Call signature::
      ax = twin()
    create a twin of Axes for generating a plot with a shared
    x-axis and y-axis.  
    The x-axis (y-axis) of ax will have ticks on bottom (left)
    and the returned axes will have ticks on the top (right). 
    .. note::
        For those who are 'picking' artists while using twin, pick
        events are only called for the artists in the top-most axes.
    
        This function will be wrong when the axis-limits are changed by xticks. 
        This can be corrected by call `xlim` to reset the limits.
    """
    assert show in ['x', 'y', 'xy']
    if ax is None:
        ax = plt.gca()
    ax.xaxis.tick_bottom()
    ax.yaxis.tick_left()

    ax2 = ax._make_twin_axes()
    ax2._shared_x_axes.join(ax2, ax)
    ax2._shared_y_axes.join(ax2, ax)
    ax2._adjustable = 'datalim'
    ax2.set_xlim(ax.get_xlim(), emit=False, auto=False)
    ax2.set_ylim(ax.get_ylim(), emit=False, auto=False)
    ax2.xaxis._set_scale(ax.xaxis.get_scale())
    ax2.yaxis._set_scale(ax.yaxis.get_scale())

    ax2.xaxis.tick_top()
    ax2.yaxis.tick_right()
    ax2.xaxis.set_label_position('top')
    ax2.yaxis.set_label_position('right')
    ax2.yaxis.set_offset_position('right')

    ax2.patch.set_visible(False)
    if show == 'x':
        ax2.yaxis.set_visible(False)
    elif show == 'y':
        ax2.xaxis.set_visible(False)
    return ax2

以上是关于python twin.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python