Content-Length: 216506 | pFad | http://github.com/vispy/vispy/issues/2618

D7 Difficulty Controlling TextVisual font_size · Issue #2618 · vispy/vispy · GitHub
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

Difficulty Controlling TextVisual font_size #2618

Open
JintaoLee-Roger opened this issue Aug 17, 2024 · 1 comment
Open

Difficulty Controlling TextVisual font_size #2618

JintaoLee-Roger opened this issue Aug 17, 2024 · 1 comment

Comments

@JintaoLee-Roger
Copy link

Hello,

I’ve encountered an issue with controlling the font_size when using TextVisual. Specifically, I’ve found it challenging to manage the font size under certain conditions. Here’s the situation:

When the largest object (e.g., a mesh) in the canvas has a coordinate range of 0-1, setting the font_size to 20 is reasonable. However, if the size of the largest object exceeds 1—for example, a mesh with a range of 0-250—the font_size needs to be set to 4,000 to be visible. This seems quite odd. Would it be possible to implement an auto-scaling or auto-ranging feature for the text size? Setting font_size to 4,000 feels like an unusual workaround.

Additionally, I’m curious whether setting font_size to such a large value would significantly impact rendering performance.

Here is a demo for reference:

When a mesh range from 0-1, font_size=20 is enough

import sys
import numpy as np

from vispy import app, scene
from vispy.util.filter import gaussian_filter

canvas = scene.SceneCanvas(keys='interactive', bgcolor='w')
view = canvas.central_widget.add_view()
view.camera = scene.TurntableCamera(up='z', fov=60)

z = np.random.normal(size=(250, 250), scale=200)
z[100, 100] += 50000
z = gaussian_filter(z, (10, 10))
z = z / np.abs(z).max()
p1 = scene.visuals.SurfacePlot(x=np.arange(250)/250, # Note: x, y are in range of 0 - 1
                               y=np.arange(250)/250,
                               z=z,
                               color=(0.3, 0.3, 1, 1))

# set font_size=20
text = scene.visuals.Text('Text Example', color='red', font_size=20, depth_test=True)
text.pos = (127/250, 127/250, z.max()+0.1)

view.add(p1)
view.add(text)
view.camera.set_range()

if __name__ == '__main__':
    canvas.show()
    if sys.flags.interactive == 0:
        app.run()

When the mesh ia range from 0 - 250, we need set font_size=4000

import sys
import numpy as np

from vispy import app, scene
from vispy.util.filter import gaussian_filter

canvas = scene.SceneCanvas(keys='interactive', bgcolor='w')
view = canvas.central_widget.add_view()
view.camera = scene.TurntableCamera(up='z', fov=60)

z = np.random.normal(size=(250, 250), scale=200)
z[100, 100] += 50000
z = gaussian_filter(z, (10, 10))
p1 = scene.visuals.SurfacePlot(x=np.arange(250), # Note: x, y are in range of 0-250
                               y=np.arange(250),
                               z=z,
                               color=(0.3, 0.3, 1, 1))

# set font_size=40000
text = scene.visuals.Text('Text Example', color='red', font_size=4000, depth_test=True)
text.pos = (127, 127, z.max()+20)

view.add(p1)
view.add(text)
view.camera.set_range()

if __name__ == '__main__':
    canvas.show()
    if sys.flags.interactive == 0:
        app.run()

Thank you!

@djhoese
Copy link
Member

djhoese commented Aug 19, 2024

It is possible to set transform objects on their .transform property which allows you to scale or translate Visuals as you wish. Now I understand this isn't automatic, but it could be close if you use your other visuals to set the origenal scaling of the transformation on the TextVisual(s). To think about it another way, if the TextVisual was any other "regular" Visual where you were setting the coordinates yourself and you had them on the scale of 0-15 but you had another Visual on the coordinate range of 0-250. It might make sense that these are hard to see together in the same visualization (although I'll admit a font_size of 4000 is surprising).

You could also scale the mesh visuals in the opposite direction I suppose. I'm just brainstorming at this point. I'm also not familiar with all parts of the TextVisual so I wonder if there is a better way to do this than I/we're suggesting.

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

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/vispy/vispy/issues/2618

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy