MCPcopy
hub / github.com/pydata/xarray / _adjust_fig_for_guide

Method _adjust_fig_for_guide

xarray/plot/facetgrid.py:733–758  ·  view source on GitHub ↗
(self, guide)

Source from the content-addressed store, hash-verified

731 self._finalized = True
732
733 def _adjust_fig_for_guide(self, guide) -> None:
734 # Draw the plot to set the bounding boxes correctly
735 if hasattr(self.fig.canvas, "get_renderer"):
736 renderer = self.fig.canvas.get_renderer()
737 else:
738 raise RuntimeError("MPL backend has no renderer")
739 self.fig.draw(renderer)
740
741 # Calculate and set the new width of the figure so the legend fits
742 guide_width = guide.get_window_extent(renderer).width / self.fig.dpi
743 figure_width = self.fig.get_figwidth()
744 total_width = figure_width + guide_width
745 self.fig.set_figwidth(total_width)
746
747 # Draw the plot again to get the new transformations
748 self.fig.draw(renderer)
749
750 # Now calculate how much space we need on the right side
751 guide_width = guide.get_window_extent(renderer).width / self.fig.dpi
752 space_needed = guide_width / total_width + 0.02
753 # margin = .01
754 # _space_needed = margin + space_needed
755 right = 1 - space_needed
756
757 # Place the subplot axes to give space for the legend
758 self.fig.subplots_adjust(right=right)
759
760 def add_legend(
761 self,

Callers 1

add_legendMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected