Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Doc]: alpha setting for annotation TextArea #24390

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

Closed
rcomer opened this issue Nov 7, 2022 · 3 comments · Fixed by #24444
Closed

[Doc]: alpha setting for annotation TextArea #24390

rcomer opened this issue Nov 7, 2022 · 3 comments · Fixed by #24444
Milestone

Comments

@rcomer
Copy link
Member

rcomer commented Nov 7, 2022

Bug summary

I've been adding annotations following the excellent examples at AnnotationBbox demo, but I'd like to make the text box transparent. From the TextArea docs it looks like my_text_area.set(alpha=x) should work, but it doesn't seem to have any effect.

Perhaps there is another way to set this that I have missed?

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.offsetbox import TextArea, AnnotationBbox

import numpy as np

rng = np.random.default_rng()

data = rng.normal(size=30)

plt.rcdefaults()

_ , ax = plt.subplots()
ax.hist(data)

offsetbox = TextArea('Look over there!')
offsetbox.set(alpha=0.3)

ab = AnnotationBbox(offsetbox, (0.8, 0.8),
            xybox=(0, 1),
            xycoords='axes fraction',
            boxcoords='data',
            arrowprops=dict(arrowstyle="->"))

ax.add_artist(ab)

plt.show()

Actual outcome

mpl_annotation_box_alpha

Expected outcome

The text box should be transparent.

Additional information

I tried a few versions back to 3.3, but the result was the same.

Operating system

RHEL7

Matplotlib Version

3.6.2

Matplotlib Backend

QtAgg

Python version

3.8.13

Jupyter version

N/A

Installation

conda

@QuLogic
Copy link
Member

QuLogic commented Nov 8, 2022

You'll need to pass bboxprops=dict(alpha=0.3) to the AnnotationBbox. The TextArea does not draw any background.

@rcomer
Copy link
Member Author

rcomer commented Nov 8, 2022

Thanks @QuLogic, that did the trick. So I guess there isn't actually a bug here. Possibly a documentation issue? Or should we close this?

@oscargus
Copy link
Member

oscargus commented Nov 8, 2022

Seems like there arguments are not documented: bboxprops=None, arrowprops=None, fontsize=None so that can for sure be a good idea. Probably with a comment about how to make it transparent (which seems like a common enough use case).

@rcomer rcomer changed the title [Bug]: alpha setting for annotation TextArea [Doc]: alpha setting for annotation TextArea Nov 8, 2022
@QuLogic QuLogic added this to the v3.6.3 milestone Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants