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
Fix #2681 #2682
Conversation
Checks if current axis is colorbar before trying to set the name
Codecov Report
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
|
Where does the string |
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:
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) |
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. |
Great, thank you! |
Co-authored-by: Jesko Wagner <35219306+jeskowagner@users.noreply.github.com> Co-authored-by: Philipp A <flying-sheep@web.de>
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.