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

Unicode support in the method add.text() of mne.viz.brain #12543

Closed
Jieli12 opened this issue Apr 16, 2024 · 3 comments
Closed

Unicode support in the method add.text() of mne.viz.brain #12543

Jieli12 opened this issue Apr 16, 2024 · 3 comments
Labels

Comments

@Jieli12
Copy link

Jieli12 commented Apr 16, 2024

Describe the new feature or enhancement

When I run the following command:
brain.add_text(0.1, 0.9, "chinese\u2190中文", color="black", font_size=10)

The added text only shows chinese, see below
Screenshot 2024-04-16 at 16 47 17

However, I expect the added text to be chinese <- 中文. Would you please add this feature?

Describe your proposed implementation

I am not a Python expert, but I found that the Python package PyVista also has the method add_text() here. Maybe it can offer some thought on how to add this new feature.

Describe possible alternatives

None.

Additional context

No response

@Jieli12 Jieli12 added the ENH label Apr 16, 2024
Copy link

welcome bot commented Apr 16, 2024

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@drammock
Copy link
Member

Sorry for the slow reply! This is a bug of PyVista, not MNE-Python. Under the hood we are already calling exactly the pyvista.Plotter.add_text() method that you linked to. Note that if you modify this PyVista tutorial to use your text, it also fails to print the arrow and the hanzi:

import pyvista as pv
from pyvista import examples

mesh = examples.download_st_helens().warp_by_scalar()
cpos = [(575848.0, 5128459.0, 22289.0), (562835.0, 5114981.5, 2294.5), (-0.5, -0.5, 0.7)]
p = pv.Plotter(shape=(1, 2), window_size=[1500, 500])

p.subplot(0, 0)
p.add_mesh(mesh, show_scalar_bar=False)
p.add_text("chinese\u2190中文")  # <- CHANGED HERE

p.subplot(0, 1)
specular = 1.0
p.add_mesh(mesh, specular=specular, show_scalar_bar=False)
p.add_text(f'Specular of {specular}')

p.link_views()
p.view_isometric()
p.show(cpos=cpos)

Screenshot_2024-05-10_15-35-23

I recommend opening a similar issue on PyVista repository.

@Jieli12
Copy link
Author

Jieli12 commented May 10, 2024

Would you please run the following code?

import pyvista as pv
from pyvista import examples

font = "Microsoft YaHei"
mesh = examples.download_st_helens().warp_by_scalar()
cpos = [
    (575848.0, 5128459.0, 22289.0),
    (562835.0, 5114981.5, 2294.5),
    (-0.5, -0.5, 0.7),
]
p = pv.Plotter(shape=(1, 2), window_size=[1500, 500])

p.subplot(0, 0)
p.add_mesh(mesh, show_scalar_bar=False)
p.add_text(
    "chinese\u2190中文", font_file="/System/Library/Fonts/STHeiti Medium.ttc"
)  # <- CHANGED HERE, specifying the  `font_file`

p.subplot(0, 1)
specular = 1.0
p.add_mesh(mesh, specular=specular, show_scalar_bar=False)
p.add_text(f"Specular of {specular}")

p.link_views()
p.view_isometric()
p.show(cpos=cpos)

It shows
a

Could you please also add the argument font_file in brain.add_text() function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants