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

Unreadably small plot axis labels on Dell XPS-15 laptop running Windows 10 #819

Open
capn-freako opened this issue Oct 20, 2021 · 13 comments

Comments

@capn-freako
Copy link

Problem Description
When running a Chaco-based GUI application on my Dell XPS-15 Wiindows10 laptop, I'm getting unreadably small plot axis labels.

Reproduction Steps:

Run a Chaco-based GUI app. on a Dell XPS-15 running Windows 10.

# Code to reproduce issue here

Expected behavior:

The same application run on a MacBook or under Linux produces acceptably sized plot axis labels.

OS, Python version: [Enter OS name and Python version]

Windows 10
Python 3.8

@corranwebster
Copy link
Contributor

corranwebster commented Oct 20, 2021

What version of Enable are you using, what Kiva backend (I'm guessing "image" if you aren't doing anything special), and what toolkit (Qt or Wx)?

We haven't been seeing this issue on other windows machines, but you may have some combination of screen resolution, toolkit, OS and font availability that is causing this.

Recent updates added HiDPI support for Qt, but it is a comparatively new feature and so there may be bugs. There is at least one known issue with the support when the resolution changes: enthought/enable#864

There was also a change to the way font lookup is done in Kiva recently which may be impacting this.

Things to try:

  • use a different backend (eg. "celiagg" or "qpainter" - if on Qt - may give better results) - this can be set via the ETS_TOOLKIT environment variable, or via ETSConfig.kiva_backend in traits.ets_config.api (this should be set very early in application start, ideally before any Kiva, Enable or Chaco imports). If "celiagg" works for you, then the issue can probably be considered solved, as that will become the default "image" backend at the next major release.
  • try changing the font and size that you are using for the axis labels to one that you know that you have on your system (in case it is a font discovery issue). If this fixes things, then that helps narrow down the causes, but it would still be a bug in Kiva.
  • turn off HiDPI support in the ComponentEditor with this switch: https://docs.enthought.com/enable/api/enable.component_editor.html?highlight=hidpi#enable.component_editor.ComponentEditor.high_resolution. Your plots won't be high-resolution, but it should hopefully resolve. This is also a work-around, not a fix, but hopefully it will give you a short term solution.

This is likely an Enable issue, not a Chaco one, per-se, so it would be good if you could open an issue in the Enable repository with a reference to this issue.

@capn-freako
Copy link
Author

capn-freako commented Oct 20, 2021

Thank you for the detailed response, @corranwebster !

My System & Configuration Info

  • Enable: v5.2.1
  • Kiva backend: image
  • Toolkit: qt4
  • OS: Windows 10
  • Screen resolution: 3840x2160

Things To Try

Explicit setting of toolkit/backend.

Adding the following code to the very beginning of my Python source file:

from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt.celiagg'

results in the following backtrace:

Traceback (most recent call last):
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\capnf\Documents\GitHub\PyBERT\pybert\__main__.py", line 2, in <module>
    from pybert.pybert      import PyBERT
  File "C:\Users\capnf\Documents\GitHub\PyBERT\pybert\pybert.py", line 29, in <module>
    from chaco.api import ArrayPlotData, GridPlotContainer
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\chaco\api.py", line 343, in <module>
    from chaco.overlays.api import (
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\chaco\overlays\api.py", line 63, in <module>
    from chaco.overlays.layers.api import (
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\chaco\overlays\layers\api.py", line 11, in <module>
    from .status_layer import ErrorLayer, StatusLayer, WarningLayer
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\chaco\overlays\layers\status_layer.py", line 18, in <module>
    from enable.savage.svg.backends.kiva.renderer import Renderer as KivaRenderer
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\enable\savage\svg\backends\kiva\renderer.py", line 36, in <module>
    class CompiledPath(KivaCompiledPath):
  File "C:\Users\capnf\AppData\Local\Continuum\anaconda3\envs\pybert-dev\lib\site-packages\enable\savage\svg\backends\kiva\renderer.py", line 38, in CompiledPath
    AddPath = KivaCompiledPath.add_path
AttributeError: type object 'Unimplemented' has no attribute 'add_path'

However, the following code works and fixes the plot axis label font size problem!

from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt.qpainter'

Question: What do I need to do/install, in order to be able to try the celiagg backend?

Explicit Font/Size Choice

Note: The following applies when I'm still using the image backend.

I am able to get correctly sized plot axis labels on my high-res. Windows 10 machine, using the following Python code addition:

LARGE_FONTS = True
title_size = 36
axis_size  = 28
tick_size  = 26

    # Temporary hack, to fix small font size problem on high-res Windows laptop display.
    if LARGE_FONTS:
        for p in [  plot2,
                    plot9,
                    plot_clk_per_hist,
                    {snip}
                    plot_bathtub_dfe]:
            p.title_font.size                 = title_size
            p.index_axis.title_font.size      = axis_size
            p.value_axis.title_font.size      = axis_size
            p.index_axis.tick_label_font.size = tick_size
            p.value_axis.tick_label_font.size = tick_size
            p.legend.font.size                = axis_size

However, the plot axis labels then become clownishly large on the other two platforms (Linux & MacOS).

Disabling HiDPI Support in ComponentEditor

(I have not yet tried this.)

Cross-linked Issue on Enable Repo.

enthought/enable#886

@capn-freako
Copy link
Author

capn-freako commented Oct 21, 2021

After implementing the solution noted above (ETSConfig.toolkit = 'qt.qpainter'), I'm having some trouble w/ text overlap and cutoff:

Capture

How can I deal w/ this?
Is there something equivalent to the tight-layout option from matplotlib?

==> Found my answer:

GridPlotContainer(..., spacing=(50,50))

@capn-freako
Copy link
Author

capn-freako commented Oct 21, 2021

Hmmm, my HTML items are still vexed by illegibly small text; any thoughts?

==> Changing the item type from: HTML, to: String, has solved this.

@capn-freako
Copy link
Author

How do I retrieve the system DPI from within my Traits/UI application?

@corranwebster
Copy link
Contributor

Question: What do I need to do/install, in order to be able to try the celiagg backend?

Apologies, I'm used to having that installed on my system: pip install celiagg hopefully works, but I'm not sure about Windows; not sure if there is a Conda build, but it is available via the Enthought Distribution Manager if you need to set up a test environment. The PyPI page is here: https://pypi.org/project/celiagg/

Thanks for the other reports. It sounds like there may be an issue with font sizes/font rendering in HiDPI mode for the "image" backend. I'm very interested in what happens with the celiagg backend, as this is likely to indicate whether it is a problem with the older backend code, or is also present in newer code.

@corranwebster
Copy link
Contributor

After implementing the solution noted above (ETSConfig.toolkit = 'qt.qpainter'), I'm having some trouble w/ text overlap and cutoff:

The general solution for this is to increase the appropriate padding value of the plot - titles etc. are drawn in the padding region of the component.

How do I retrieve the system DPI from within my Traits/UI application?

You'll need to drop down to the Qt level, it's not exposed in TraitsUI as we try to abstract that sort of thing away as much as possible. I don't recall the exact way to do it, however.

Enable/Chaco will give you what they think the scaling factor should be via the base_pixel_scale of the window.

Hmmm, my HTML items are still vexed by illegibly small text; any thoughts?

This is a TraitsUI HTMLEditor? Again, we haven't seen that before, and pretty much all of the HTML rendering in those widgets is passed down to Qt. It might be worth looking at what you have set as your system default font for Windows?

@capn-freako
Copy link
Author

The general solution for this is to increase the appropriate padding value of the plot - titles etc. are drawn in the padding region of the component.

So, this:

    plot_h_tune = Plot(plotdata, padding_bottom=75)

doesn't appear to have any effect.

@capn-freako
Copy link
Author

Apologies, I'm used to having that installed on my system: pip install celiagg hopefully works, but I'm not sure about Windows; not sure if there is a Conda build, but it is available via the Enthought Distribution Manager if you need to set up a test environment. The PyPI page is here: https://pypi.org/project/celiagg/

Conda does offer the celiagg package; the command: conda install celiagg worked.

Thanks for the other reports. It sounds like there may be an issue with font sizes/font rendering in HiDPI mode for the "image" backend. I'm very interested in what happens with the celiagg backend, as this is likely to indicate whether it is a problem with the older backend code, or is also present in newer code.

The celiagg backend also produces unacceptably small font sizes in the plot axis labels, on my Windows high DPI display, although they are not as small as with the image backend.

@capn-freako
Copy link
Author

Enable/Chaco will give you what they think the scaling factor should be via the base_pixel_scale of the window.

How do I access the window element?
It doesn't appear to be an attribute of a HasTraits subclass:

class PyBERT(HasTraits):
...
    def log_information(self):
        """Log the system information."""
        ...
        self.log(f"Pixel Scale: {self.window.base_pixel_scale}")
Traceback (most recent call last):
{snip}
AttributeError: 'PyBERT' object has no attribute 'window'

@jdmarch
Copy link

jdmarch commented Oct 23, 2021

@capn-freako not sure, but it's possible that @corranwebster will be AFK for the next week...

@corranwebster
Copy link
Contributor

How do I access the window element?

It will be available on your Plot object once the UI is created. There are other ways to get at it, but this is probably the easiest.

    plot_h_tune = Plot(plotdata, padding_bottom=75)

Try something much larger than 75 - I think the default is 70, so you won't see much difference.

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

3 participants