-
-
Save prabathbr/49cbc950705aae7d1869097b1d98815e to your computer and use it in GitHub Desktop.
Identity line for matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
def identity_line(ax=None, ls='--', *args, **kwargs): | |
# see: https://stackoverflow.com/q/22104256/3986320 | |
ax = ax or plt.gca() | |
identity, = ax.plot([], [], ls=ls, *args, **kwargs) | |
def callback(axes): | |
low_x, high_x = ax.get_xlim() | |
low_y, high_y = ax.get_ylim() | |
low = min(low_x, low_y) | |
high = max(high_x, high_y) | |
identity.set_data([low, high], [low, high]) | |
callback(ax) | |
ax.callbacks.connect('xlim_changed', callback) | |
ax.callbacks.connect('ylim_changed', callback) | |
return ax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment