Skip to content

Gtk3Cairo messes up Gtk3 rendering #18078

Closed as not planned
Closed as not planned

Description

@jeremydufour

Bug report

Bug summary

I tried to use Gtk3Cairo backend to display a matplotlib figure on my Gtk3 window.
When the FigureCanvas is added and drawn by Gtk, the rendered size of objects seems to double (see figures).

Code for reproduction

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk

from matplotlib.figure import Figure
import random as Rdm
from matplotlib.backends.backend_gtk3cairo import FigureCanvas


def getDiagram():
    f = Figure(figsize=(100, 100))
    plot = f.add_subplot(1, 1, 1)
    # Add figure

    labels = ['Mo', 'Tu', 'We', 'Th', 'Fr','Sa', 'Su']
    width = 0.93       # the width of the bars
    data = [[1,15],[17,22], [3,7]]
    
    for i in range(0,len(data)):
        plotColor = Gdk.RGBA(Rdm.random(),Rdm.random(),Rdm.random(),1)

        plot.bar(labels, data[i][0], width, yerr=None, bottom=data[i][1],
                 color=(plotColor.red, plotColor.green, plotColor.blue))
    
    plot.set_frame_on(True)
    plot.yaxis.set_visible(True)
    plot.set_ylim(0.0,24.0)
    return f
#END getDiagram


class testWin(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(500,600)
        self.show()

        grid = Gtk.Grid()
        self.add(grid)

        fig = getDiagram()
        
        canvas = FigureCanvas(fig)
        canvas.set_size_request(200,200)

        topButton = Gtk.Button(label="Button Top")
        grid.attach(topButton,0,0,2,1)
        
        grid.attach(canvas,0,1,2,1)
        #grid.attach(Gtk.Label("Test"),0,1,2,1)

        botButton = Gtk.Button(label="Button Bottom")
        grid.attach(botButton,0,2,2,1)

        self.show_all()
#END testWin

win = testWin()
win.connect("destroy",Gtk.main_quit)
win.show_all()
Gtk.main()

Actual outcome

Capture d’écran 2020-07-26 à 17 47 39

Expected outcome

Capture d’écran 2020-07-26 à 17 48 01

The size of rendered objects shouldn't change when I add the FigureCanvas.

Matplotlib version

  • Operating system: macOS 10.13.4
  • Matplotlib version: 3.3.0
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.8.4
  • Other libraries:
    pycairo: 1.19.1
    PyGObject: 3.36.1

I installed matplotlib and the other Python libraries with pip3

Activity

  1. QuLogic commented on Jul 29, 2020

    @QuLogic
    Member

    I guess you have a HiDPI/retina screen? I can't reproduce on Linux, but don't have HiDPI, and setting GDK_SCALE=2 scales everything else correctly.

  2. jeremydufour commented on Jul 29, 2020

    @jeremydufour
    Author

    Yes I have a Retina screen which is HiDPI. I tried exporting GDK_SCALE and GDK_DPI_SCALE before running my script but nothing changes. Maybe those two parameters can be accessed with Python ?

  3. tacaswell commented on Jul 29, 2020

    @tacaswell
    Member

    I can not reproduce this on linux and I see that GDK_SCALE=2 scales things correctly.

    How did you install Python and gtk?

  4. jeremydufour commented on Jul 29, 2020

    @jeremydufour
    Author

    I can not reproduce this on linux and I see that GDK_SCALE=2 scales things correctly.

    How did you install Python and gtk?

    I installed Python 3.8 with the installer from python.org (no homebrew/macports). I installed Gtk, Cairo, GLib and Gobject-introspection with homebrew.

  5. QuLogic commented on Sep 8, 2021

    @QuLogic
    Member

    Maybe #20988 will fix this?

    In experimenting with that, I see that GDK_SCALE only has an effect with X11 and not Wayland. Perhaps the same is true of the Quartz backend?

  6. github-actions commented on Aug 14, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  7. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions