Skip to content

Commit

Permalink
Merge pull request #71 from sadielbartholomew/cbar-cutoff-fix
Browse files Browse the repository at this point in the history
Create & apply testing decorator for plot comparison, w/bug fix
  • Loading branch information
sadielbartholomew authored Aug 13, 2024
2 parents 4369dfe + 95a15b7 commit 5d6bfe1
Show file tree
Hide file tree
Showing 48 changed files with 128 additions and 197 deletions.
50 changes: 21 additions & 29 deletions cfplot/cfplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9906,54 +9906,46 @@ def cbar(

left, bottom, width, height = this_plot.get_position().bounds

exclude_vprojs = ["cyl", "lcc", "moll", "merc", "ortho", "robin"]
if orientation == "horizontal":
if (
plotvars.plot_type > 1
or plotvars.plot == 0
or plotvars.proj not in exclude_vprojs
):
if plotvars.plot_type > 1 or plotvars.plot == 0:
this_plot.set_position(
[left, bottom + fraction, width, height - fraction]
)

if plotvars.plot_type == 1 and plotvars.proj in exclude_vprojs:
# Move plot up if aspect ratio is < 1.5
lonrange = plotvars.lonmax - plotvars.lonmin
latrange = plotvars.latmax - plotvars.latmin

if (lonrange / latrange) <= 1.5:
this_plot.set_position(
[left, bottom + 0.08, width, height - 0.12]
)
left, bottom, width, height = (
this_plot.get_position().bounds
)

ax1 = plotvars.master_plot.add_axes(
[
left + width * (1.0 - shrink) / 2.0,
bottom - fraction * (1.0 - anchor),
bottom,
width * shrink,
thick,
]
)

if plotvars.plot_type > 1 or plotvars.plot_type == 0:
this_plot.set_position(
[left, bottom + fraction, width, height - fraction]
if plotvars.plot_type == 1:
# If the plot is too square in terms of aspect ratio, it
# will push the colour bar down and it can be cut off, so
# move the plot up in these cases. Use height and width
# ratio since this represents the matplotlib object
# position differences, so is the best way to measure.
left, bottom, width, height = (
this_plot.get_position().bounds
)
# Empirical sweet spot: roughly where plot area is taller
# than it is wide, including when plot area is roughly square
if height / width >= 0.9:
this_plot.set_position(
[left, bottom + fraction, width, height - fraction]
)
left, bottom, width, height = (
this_plot.get_position().bounds
)

ax1 = plotvars.master_plot.add_axes(
[
left + width * (1.0 - shrink) / 2.0,
# b - fraction * (1.0 - anchor),
bottom,
bottom + fraction * (anchor - 1.0),
width * shrink,
thick,
]
)

else:
ax1 = plotvars.master_plot.add_axes(
[
Expand Down Expand Up @@ -10215,7 +10207,7 @@ def irregular_window(field, lons, lats):
lons_irregular = np.concatenate([lons_irregular, lons_new])
lats_irregular = np.concatenate([lats_irregular, lats_new])

# Add to the right if a fiull globe is being plotted
# Add to the right if a full globe is being plotted
# The 359.99 here is needed or Cartopy will map 360 back to 0

if plotvars.lonmax - plotvars.lonmin == 360:
Expand Down
Binary file removed cfplot/test/reference-example-images/ref_fig34.png
Binary file not shown.
Binary file removed cfplot/test/reference-example-images/ref_fig36.png
Binary file not shown.
Binary file removed cfplot/test/reference-example-images/ref_fig37.png
Binary file not shown.
Loading

0 comments on commit 5d6bfe1

Please sign in to comment.