enthought / chaco

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

Better handling of "Dark Mode" #899

Open corranwebster opened 1 year ago

corranwebster commented 1 year ago

Problem Description

When running on Mac in Dark Mode with recent Qt versions, plots render like this:

image

Reproduction Steps:

The is produced by this code:

from numpy import linspace, sin
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
from chaco.api import Plot, ArrayPlotData
from enable.api import ComponentEditor

class LinePlot(HasTraits):
    plot = Instance(Plot)

    traits_view = View(
        Item('plot', editor=ComponentEditor(), show_label=False),
        width=500,
        height=500,
        resizable=True,
        title="Chaco Plot",
    )

    def _plot_default(self):
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        plot = Plot(plotdata)
        plot.plot(("x", "y"), type="line", color="blue")
        plot.title = "sin(x) * x^3"
        return plot

if __name__ == "__main__":
    LinePlot().configure_traits()

Expected behavior:

At a minimum we should be defaulting to painting the padded area white so the labels are visible. Better would be to detect the background color of the window and adapt rendering appropriately (which would require a default "dark-mode" palette for all drawing, which is significant work)

OS, Python version: MacOS, all Python versions.