-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added bbox_inches flag. Defaults to None #95
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -216,13 +216,14 @@ def combine_frames_into_movie( | |||||||||
# return fig | ||||||||||
|
||||||||||
|
||||||||||
def save_single_frame(fig, frame, odir=None, frame_pattern="frame_%05d.png", dpi=100): | ||||||||||
def save_single_frame(fig, frame, odir=None, frame_pattern="frame_%05d.png", dpi=100, bbox_inches=None): | ||||||||||
"""Saves a single frame of data from an already-created figure and then closes the figure""" | ||||||||||
fig.savefig( | ||||||||||
os.path.join(odir, frame_pattern % (frame)), | ||||||||||
dpi=dpi, | ||||||||||
facecolor=fig.get_facecolor(), | ||||||||||
transparent=True, | ||||||||||
bbox_inches=bbox_inches, | ||||||||||
) | ||||||||||
# I am trying everything to *wipe* this figure, hoping that it could | ||||||||||
# help with the dask glitches I experienced earlier. | ||||||||||
|
@@ -243,6 +244,7 @@ def __init__( | |||||||||
pixelwidth=1920, | ||||||||||
pixelheight=1080, | ||||||||||
dpi=200, | ||||||||||
bbox_inches=None, | ||||||||||
frame_pattern="frame_%05d.png", | ||||||||||
fieldname=None, | ||||||||||
input_check=True, | ||||||||||
|
@@ -264,6 +266,9 @@ def __init__( | |||||||||
Movie size. | ||||||||||
dpi : int | ||||||||||
Movie resolution. | ||||||||||
bbox_inches: str | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Same as bbox_inches flag in savefig from matplotlib. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Bounding box in inches: only the given portion of the figure is saved. If 'tight', try to figure out the tight bbox of the figure. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||||||||||
frame_pattern : str | ||||||||||
Filename pattern when saving frames. | ||||||||||
fieldname | ||||||||||
|
@@ -275,6 +280,7 @@ def __init__( | |||||||||
self.pixelwidth = pixelwidth | ||||||||||
self.pixelheight = pixelheight | ||||||||||
self.dpi = dpi | ||||||||||
self.bbox_inches = bbox_inches | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I would prefer to carry |
||||||||||
self.width = self.pixelwidth / self.dpi | ||||||||||
self.height = self.pixelheight / self.dpi | ||||||||||
self.frame_pattern = frame_pattern | ||||||||||
|
@@ -372,7 +378,14 @@ def save_frames_serial(self, odir, progress=False): | |||||||||
|
||||||||||
for timestep in frame_range: | ||||||||||
fig, ax, pp = self.render_single_frame(timestep) | ||||||||||
save_single_frame(fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi) | ||||||||||
save_single_frame( | ||||||||||
fig, | ||||||||||
timestep, | ||||||||||
odir=odir, | ||||||||||
frame_pattern=self.frame_pattern, | ||||||||||
dpi=self.dpi, | ||||||||||
bbox_inches=self.bbox_inches, | ||||||||||
) | ||||||||||
|
||||||||||
def save_frames_parallel(self, odir, parallel_compute_kwargs=dict()): | ||||||||||
""" | ||||||||||
|
@@ -415,7 +428,14 @@ def _save_single_frame_parallel(xr_array, framedim): | |||||||||
) # get index of chunk in framedim | ||||||||||
|
||||||||||
fig, ax, pp = self.render_single_frame(timestep) | ||||||||||
save_single_frame(fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi) | ||||||||||
save_single_frame( | ||||||||||
fig, | ||||||||||
timestep, | ||||||||||
odir=odir, | ||||||||||
frame_pattern=self.frame_pattern, | ||||||||||
dpi=self.dpi, | ||||||||||
bbox_inches=self.bbox_inches, | ||||||||||
) | ||||||||||
|
||||||||||
return time_of_chunk | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might add other kwargs for
.savefig()
here (see comments below). If so should we have some dict that catches allsave_kwargs=None
(we can then set defaults we like in the init)? Otherwise we might be accumulating a bunch of input arguments and the signature of this might become unruly?