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

Fix #2681 #2682

Merged
merged 2 commits into from Oct 16, 2023
Merged

Fix #2681 #2682

merged 2 commits into from Oct 16, 2023

Conversation

jeskowagner
Copy link
Contributor

Checks if current axis is colorbar before trying to set the name, see #2681.
This might not be the best solution and does not yet integrate a unit test.

Checks if current axis is colorbar before trying to set the name
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Merging #2682 (e762eac) into master (616d580) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

❗ Current head e762eac differs from pull request most recent head 6b305e1. Consider uploading reports for the commit 6b305e1 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2682      +/-   ##
==========================================
- Coverage   71.98%   71.97%   -0.02%     
==========================================
  Files         108      108              
  Lines       11905    11907       +2     
==========================================
  Hits         8570     8570              
- Misses       3335     3337       +2     
Files Coverage Δ
scanpy/plotting/_tools/scatterplots.py 86.82% <0.00%> (-0.42%) ⬇️

@flying-sheep
Copy link
Member

flying-sheep commented Oct 12, 2023

Where does the string '<colorbar>' come from?

@jeskowagner
Copy link
Contributor Author

Continuing from the reproducible example in #2681, I debugged from this line onwards. I.e. we can do

from scanpy.plotting import embedding

label_dict = {
    'PC{}'.format(i + 1): 'PC{} ({}%)'.format(i + 1, round(v * 100, 2))
    for i, v in enumerate(adata.uns['pca']['variance_ratio'])
}
# {'PC1': 'PC1 (27.22%)', 'PC2': 'PC2 (23.11%)', 'PC3': 'PC3 (18.64%)', 'PC4': 'PC4 (15.85%)'}

fig = embedding(adata, 'pca', return_fig=True, color="a")

To then get the label:

for i, ax in enumerate(fig.axes):
    print(f"Axis {i}")
    print(f"Label: {ax.get_label()}")
    print(f"x: {ax.xaxis.get_label().get_text()}")
    print(f"y: {ax.yaxis.get_label().get_text()}")
    print("")

Which prints:

Axis 0
Label: 
x: PC1
y: PC2

Axis 1
Label: <colorbar>
x: 
y: 

An alternative fix could also check for key presence in the label_dict:

for ax in fig.axes:
    xlab = ax.xaxis.get_label().get_text()
    if xlab in label_dict:
        ax.set_xlabel(xlab)
    ylab = ax.yaxis.get_label().get_text()
    if ylab in label_dict:
        ax.set_ylabel(ylab)

@flying-sheep
Copy link
Member

I think the alternative version is safer, as it’ll work even if they change the format of that autogenerated label.

Unless they document it somewhere that it’s that, I assume it’s an implementation detauil.

@flying-sheep flying-sheep added this to the 1.9.6 milestone Oct 16, 2023
@flying-sheep flying-sheep enabled auto-merge (squash) October 16, 2023 09:04
@flying-sheep flying-sheep merged commit 8353e45 into scverse:master Oct 16, 2023
9 of 10 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/scanpy that referenced this pull request Oct 16, 2023
@jeskowagner
Copy link
Contributor Author

Great, thank you!

flying-sheep added a commit that referenced this pull request Oct 16, 2023
Co-authored-by: Jesko Wagner <35219306+jeskowagner@users.noreply.github.com>
Co-authored-by: Philipp A <flying-sheep@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants