8000 Gtk3Cairo messes up Gtk3 rendering · Issue #18078 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Gtk3Cairo messes up Gtk3 rendering #18078
Closed as not planned
Closed as not planned
@jeremydufour

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

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

      0