mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

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

Open Jieli12 opened this issue 1 year ago • 5 comments

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 avatar Apr 16 '24 15:04 Jieli12

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

welcome[bot] avatar Apr 16 '24 15:04 welcome[bot]

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.

drammock avatar May 10 '24 20:05 drammock

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?

Jieli12 avatar May 10 '24 22:05 Jieli12

I'm very sorry, this fell off my radar. I can confirm that the pyvista MWE does work if you directly specify the font file. So I guess we need to expose that param in the MNE API.

drammock avatar Oct 31 '25 21:10 drammock

@drammock I don't see this as a blocker for release so pushing to 1.12

larsoner avatar Nov 20 '25 16:11 larsoner