def add_plot_boundary(ax, padding=0.125): """Add a buffer of empty space around a plot boundary. .. note:: This only uses ``line`` data from the axis. It **could** use ``patch`` data, but doesn't at this time. Args: ax (matplotlib.artist.Artist): A matplotlib axis. padding (Optional[float]): Amount (as a fraction of width and height) of padding to add around data. Defaults to ``0.125``. """ nodes = np.asfortranarray( np.vstack([line.get_xydata() for line in ax.lines]).T) left, right, bottom, top = _helpers.bbox(nodes) center_x = 0.5 * (right + left) delta_x = right - left center_y = 0.5 * (top + bottom) delta_y = top - bottom multiplier = (1.0 + padding) * 0.5 ax.set_xlim(center_x - multiplier * delta_x, center_x + multiplier * delta_x) ax.set_ylim(center_y - multiplier * delta_y, center_y + multiplier * delta_y)
def make_plot(name, segment, index, save_plot): figure = plt.figure() ax = figure.gca() (line, ) = ax.plot([0, 1], [0, 1], alpha=0.0, color=BLUE) ax.fill_between([0, 1], [0, 0], [1, 1], alpha=0.5, color=line.get_color()) (line, ) = ax.plot(segment[0, :], segment[1, :], color=GREEN) ax.plot( segment[0, 0], segment[1, 0], marker="o", linestyle="None", color=line.get_color(), ) left_, right_, bottom_, top_ = _helpers.bbox(segment) ax.fill_between( [left_, right_], [bottom_, bottom_], [top_, top_], alpha=0.5, color=line.get_color(), ) ax.axis("scaled") ax.set_xlim(-1.125, 2.125) ax.set_ylim(-1.125, 2.125) if save_plot: utils.save_fig(f"test_{name}{index:02d}") else: plt.title(name.replace("_", r"\_")) plt.show() plt.close(figure)
def make_plot(segment, index): # NOTE: We import the plotting library at runtime to # avoid the cost for users that only want to compute. # The ``matplotlib`` import is a tad expensive. import matplotlib.pyplot as plt import seaborn seaborn.set() # Required in `seaborn >= 0.8` figure = plt.figure() ax = figure.gca() line, = ax.plot([0, 1], [0, 1], alpha=0.0) ax.fill_between([0, 1], [0, 0], [1, 1], alpha=0.5, color=line.get_color()) line, = ax.plot(segment[0, :], segment[1, :]) ax.plot( segment[0, 0], segment[1, 0], marker="o", linestyle="None", color=line.get_color(), ) left_, right_, bottom_, top_ = _helpers.bbox(segment) ax.fill_between( [left_, right_], [bottom_, bottom_], [top_, top_], alpha=0.5, color=line.get_color(), ) ax.axis("scaled") ax.set_xlim(-1.125, 2.125) ax.set_ylim(-1.125, 2.125) if CONFIG.save_plot: extra = "{:02d}".format(index) CONFIG.save_fig(extra=extra) else: plt.title(CONFIG.current_test) plt.show() plt.close(figure)