Skip to content

Commit

Permalink
Add option to plot multiple logos or one (#137)
Browse files Browse the repository at this point in the history
* add option to plot multiple logos or one

* change version requirements for pip
  • Loading branch information
kevindougherty-noaa committed Jul 25, 2023
1 parent d136690 commit 9b67563
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
lfs: true

# Install emcpy
- name: Upgrade pip
run: $CONDA/bin/pip3 install --upgrade pip
#- name: Upgrade pip
# run: $CONDA/bin/pip3 install --upgrade pip
- name: Install emcpy and dependencies
run: |
$CONDA/bin/pip3 install --use-deprecated=legacy-resolver -r requirements-github.txt --user .
Expand Down
12 changes: 6 additions & 6 deletions requirements-github.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pyyaml>=6.0
pycodestyle==2.9.1
netCDF4==1.6.1
pycodestyle>=2.9.1
netCDF4>=1.6.1
matplotlib==3.5.2
cartopy==0.21.1
scikit-learn==1.1.2
xarray==2022.6.0
cartopy>=0.21.1
scikit-learn>=1.1.2
xarray>=2022.6.0
pytest
Shapely
pdoc
seaborn==0.12.2
seaborn>=0.12.2
sphinx
sphinx_rtd_theme
sphinx_gallery
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ install_requires =
scikit-learn
pdoc
matplotlib
Cython
cartopy
tests_require =
pytest
Expand Down
49 changes: 33 additions & 16 deletions src/emcpy/plots/create_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def add_suptitle(self, text, **kwargs):
self.fig.suptitle(text, **kwargs)

def plot_logo(self, loc, which='noaa/nws',
zoom=1, alpha=0.5):
subplot_orientation='last', zoom=1, alpha=0.5):
"""
Add branding logo on all axes.
"""
Expand All @@ -343,6 +343,29 @@ def plot_logo(self, loc, which='noaa/nws',
'noaa/nws': 'noaa_nws_logo_150x75.png'
}

image_path = os.path.join(emcpy.emcpy_directory, 'logos', image_dict[which])
im = Image.open(image_path)

if subplot_orientation.lower() not in ['first', 'last', 'all']:
raise TypeError(f"{subplot_orientation} is not a valid input. " +
"Valid inputs include 'first', 'last', or 'all'")

ax_list = self.fig.axes

if subplot_orientation.lower() == 'first':
ax = ax_list[0]
self._display_logo(ax, im, loc, zoom, alpha)

elif subplot_orientation.lower() == 'last':
ax = ax_list[-1]
self._display_logo(ax, im, loc, zoom, alpha)

else:
for ax in ax_list:
self._display_logo(ax, im, loc, zoom, alpha)

def _display_logo(self, ax, im, loc, zoom, alpha):

loc_dict = {
'upper right': 1,
'upper left': 2,
Expand All @@ -356,23 +379,17 @@ def plot_logo(self, loc, which='noaa/nws',
'center': 10
}

image_path = os.path.join(emcpy.emcpy_directory, 'logos', image_dict[which])
im = Image.open(image_path)

ax_list = self.fig.axes

for ax in ax_list:
width, height = ax.figure.get_size_inches()*self.fig.dpi
wm_width = int(width/4) # make the watermark 1/4 of the figure size
scaling = (wm_width / float(im.size[0]))
wm_height = int(float(im.size[1])*float(scaling))
width, height = ax.figure.get_size_inches()*self.fig.dpi
wm_width = int(width/4) # make the watermark 1/4 of the figure size
scaling = (wm_width / float(im.size[0]))
wm_height = int(float(im.size[1])*float(scaling))

imagebox = OffsetImage(im, zoom=zoom, alpha=alpha)
imagebox.image.axes = ax
imagebox = OffsetImage(im, zoom=zoom, alpha=alpha)
imagebox.image.axes = ax

ao = AnchoredOffsetbox(loc_dict[loc], pad=0.1, borderpad=0.1, child=imagebox)
ao.patch.set_alpha(0)
ax.add_artist(ao)
ao = AnchoredOffsetbox(loc_dict[loc], pad=0.1, borderpad=0.1, child=imagebox)
ao.patch.set_alpha(0)
ax.add_artist(ao)

def _plot_features(self, plot_obj, feature, ax):

Expand Down

0 comments on commit 9b67563

Please sign in to comment.