enthought / chaco

Chaco is a Python package for building interactive and custom 2-D plots.
http://docs.enthought.com/chaco/
Other
292 stars 99 forks source link

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

Open capn-freako opened 3 years ago

capn-freako commented 3 years ago

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 commented 3 years ago

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: https://github.com/enthought/enable/pull/864

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

Things to try:

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 commented 3 years ago

Thank you for the detailed response, @corranwebster !

My System & Configuration Info

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.

https://github.com/enthought/enable/issues/886

capn-freako commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

corranwebster commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

jdmarch commented 3 years ago

On the substance, xref https://stackoverflow.com/questions/69688867/how-do-i-access-the-base-pixel-scale-attribute-of-a-hastraits-chaco-enable-kiva

corranwebster commented 3 years ago

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.