Skip to content

Commit

Permalink
feat: replaced seaborn with matplotlib for correlation_heatmap (#850)
Browse files Browse the repository at this point in the history
Closes #800 

### Summary of Changes

Removed seaborn with matplotlib for correlation_heatmap.
Matplotlib returns a slightly different plot, so we also replaced the
snapshot image.

But seaborn still remains as a dependency, because box_plots is still
using seaborn, see issue #849 .

---------

Co-authored-by: Lars Reimann <mail@larsreimann.com>
Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 21, 2024
1 parent abcf68a commit d4680d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/safeds/data/tabular/plotting/_table_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def correlation_heatmap(self) -> Image:
# TODO: implement using matplotlib and polars
# https://stackoverflow.com/questions/33282368/plotting-a-2d-heatmap
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

only_numerical = self._table.remove_non_numeric_columns()._data_frame.fill_null(0)

Expand All @@ -115,15 +115,18 @@ def correlation_heatmap(self) -> Image:
" automatically expanding."
),
)
fig = plt.figure()
sns.heatmap(
data=only_numerical.corr().to_numpy(),

fig, ax = plt.subplots()
heatmap = plt.imshow(
only_numerical.corr().to_numpy(),
vmin=-1,
vmax=1,
xticklabels=only_numerical.columns,
yticklabels=only_numerical.columns,
cmap="vlag",
cmap="coolwarm",
)
ax.set_xticks(np.arange(len(only_numerical.columns)), labels=only_numerical.columns)
ax.set_yticks(np.arange(len(only_numerical.columns)), labels=only_numerical.columns)
fig.colorbar(heatmap)

plt.tight_layout()

return _figure_to_image(fig)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d4680d4

Please sign in to comment.