Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Oct 18, 2024
2 parents 130bfd2 + cc3befb commit a69dca5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
30 changes: 27 additions & 3 deletions gpm/visualization/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,33 @@ def map_dataarray(
@abstractmethod
def _remove_bottom_ticks_and_labels(self, ax):
"""Method removing axis ticks and labels on the bottom of the subplots."""
raise NotImplementedError

Check warning on line 360 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L360

Added line #L360 was not covered by tests

@abstractmethod
def _remove_left_ticks_and_labels(self, ax):
"""Method removing axis ticks and labels on the left of the subplots."""
raise NotImplementedError

Check warning on line 365 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L365

Added line #L365 was not covered by tests

def map_to_axes(self, func, **kwargs):
"""Map a function to each axes."""
n_rows, n_cols = self.axs.shape
missing_bottom_plots = [not ax.has_data() for ax in self.axs[n_rows - 1]]
idx_bottom_plots = np.where(missing_bottom_plots)[0]
has_missing_bottom_plots = len(idx_bottom_plots) > 0
for i in range(0, n_rows):
for j in range(0, n_cols):
if has_missing_bottom_plots and i == n_rows and j in idx_bottom_plots:

Check warning on line 375 in gpm/visualization/facetgrid.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

CustomFacetGrid.map_to_axes has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
continue

Check warning on line 376 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L369-L376

Added lines #L369 - L376 were not covered by tests
# Otherwise apply function
func(ax=self.axs[i, j], **kwargs)

Check warning on line 378 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L378

Added line #L378 was not covered by tests

def remove_bottom_ticks_and_labels(self):
"""Remove the bottom ticks and labels from each subplot."""
self.map(lambda: self._remove_bottom_ticks_and_labels(plt.gca()))
self.map_to_axes(func=self._remove_bottom_ticks_and_labels)

Check warning on line 382 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L382

Added line #L382 was not covered by tests

def remove_left_ticks_and_labels(self):
"""Remove the left ticks and labels from each subplot."""
self.map(lambda: self._remove_left_ticks_and_labels(plt.gca()))
self.map_to_axes(func=self._remove_left_ticks_and_labels)

Check warning on line 386 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L386

Added line #L386 was not covered by tests

def remove_duplicated_axis_labels(self):
"""Remove axis labels which are not located on the left or bottom of the figure."""
Expand Down Expand Up @@ -414,7 +429,16 @@ def add_colorbar(self, **cbar_kwargs) -> None:
)
# Add ticklabel
if ticklabels is not None:
self.cbar.ax.set_yticklabels(ticklabels)
# Retrieve ticks
ticks = cbar_kwargs.get("ticks", None)
if ticks is None:
ticks = self.cbar.get_ticks()

Check warning on line 435 in gpm/visualization/facetgrid.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/facetgrid.py#L435

Added line #L435 was not covered by tests
# Remove existing ticklabels
self.cbar.set_ticklabels([])
self.cbar.set_ticklabels([], minor=True)
# Add custom ticklabels
self.cbar.set_ticks(ticks, labels=ticklabels)
# self.cbar.ax.set_yticklabels(ticklabels)

def remove_title_dimension_prefix(self, row=True, col=True):
"""Remove the dimension prefix from the subplot labels."""
Expand Down
11 changes: 10 additions & 1 deletion gpm/visualization/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,16 @@ def plot_colorbar(p, ax, cbar_kwargs=None):
# Add colorbar
cbar = plt.colorbar(p, cax=cax, ax=ax, **cbar_kwargs)
if ticklabels is not None:
_ = cbar.ax.set_yticklabels(ticklabels) if orientation == "vertical" else cbar.ax.set_xticklabels(ticklabels)
# Retrieve ticks
ticks = cbar_kwargs.get("ticks", None)
if ticks is None:
ticks = cbar.get_ticks()

Check warning on line 551 in gpm/visualization/plot.py

View check run for this annotation

Codecov / codecov/patch

gpm/visualization/plot.py#L551

Added line #L551 was not covered by tests
# Remove existing ticklabels
cbar.set_ticklabels([])
cbar.set_ticklabels([], minor=True)
# Add custom ticklabels
p.colorbar.set_ticks(ticks, labels=ticklabels)
# _ = cbar.ax.set_yticklabels(ticklabels) if orientation == "vertical" else cbar.ax.set_xticklabels(ticklabels)
return cbar


Expand Down

0 comments on commit a69dca5

Please sign in to comment.