diff --git a/src/scanpy/plotting/_baseplot_class.py b/src/scanpy/plotting/_baseplot_class.py index e14d387f84..4b31c0eef5 100644 --- a/src/scanpy/plotting/_baseplot_class.py +++ b/src/scanpy/plotting/_baseplot_class.py @@ -141,6 +141,18 @@ def __init__( self._update_var_groups() + # exlude var_names not present in adata.var_names + missing_var_names = set(self.var_names).difference(adata.var_names) + if missing_var_names: + logg.warning( + f"The following var_names are not present in adata.var_names: {missing_var_names}" + ) + self.var_names = [ + var_name + for var_name in self.var_names + if var_name not in missing_var_names + ] + self.categories, self.obs_tidy = _prepare_dataframe( adata, self.var_names,