Skip to content
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

Add option to plot multiple logos or one #137

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
CoryMartin-NOAA marked this conversation as resolved.
Show resolved Hide resolved
- 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
CoryMartin-NOAA marked this conversation as resolved.
Show resolved Hide resolved
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