Skip to content

Commit

Permalink
Set theme fix (#1886)
Browse files Browse the repository at this point in the history
* Fix #1885

* added test

* Release note
  • Loading branch information
ivirshup authored Jun 18, 2021
1 parent 4dd8de9 commit 825d910
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/1.8.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

- Fix :func:`scanpy.pl.paga_path` `TypeError` with recent versions of anndata :pr:`1047` :smaller:`P Angerer`
- Fix detection of whether IPython is running :pr:`1844` :smaller:`I Virshup`
- Fixed errors and warnings from embedding plots with small numbers of categories after `sns.set_palette` was called :pr:`1886` :smaller:`I Virshup`

.. rubric:: Deprecations

Expand Down
3 changes: 1 addition & 2 deletions scanpy/plotting/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ def _set_default_colors_for_categorical_obs(adata, value_to_plot):
-------
None
"""

categories = adata.obs[value_to_plot].cat.categories
length = len(categories)

Expand All @@ -470,7 +469,7 @@ def _set_default_colors_for_categorical_obs(adata, value_to_plot):
"'grey' color will be used for all categories."
)

adata.uns[value_to_plot + '_colors'] = palette[:length]
_set_colors_for_categorical_obs(adata, value_to_plot, palette[:length])


def add_colors_for_categorical_sample_annotation(
Expand Down
18 changes: 18 additions & 0 deletions scanpy/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import seaborn as sns
import numpy as np
import pandas as pd
from matplotlib.testing.compare import compare_images
Expand Down Expand Up @@ -1249,3 +1250,20 @@ def test_groupby_list(image_comparer):
adata, ['Gata1', 'Gata2'], groupby=['rand_cat', 'cell_type'], swap_axes=True
)
save_and_compare_images('master_dotplot_groupby_list_catorder')


def test_color_cycler(caplog):
# https://github.com/theislab/scanpy/issues/1885
import logging

pbmc = sc.datasets.pbmc68k_reduced()
colors = sns.color_palette("deep")
cyl = sns.rcmod.cycler('color', sns.color_palette("deep"))

with caplog.at_level(logging.WARNING):
with plt.rc_context({'axes.prop_cycle': cyl, "patch.facecolor": colors[0]}):
sc.pl.umap(pbmc, color="phase")
plt.show()
plt.close()

assert caplog.text == ""

0 comments on commit 825d910

Please sign in to comment.