Manuel ManUser
Manuel ManUser

Reputation: 75

Is it possible to include other backends in a Tkinter window than the Tk backends?

I recently had many issues with Tkinter backends on my MacBook Pro high DPI display. The plots look blurry. It is a known issue, which unfortunately cannot be resolved unless using a different backend as far as I am concerned.

Issue with Tk backend

Are there any other backends in Matplotlib that offer Tkinter widgets?

If not, I would also appreciate a suggestion on how to fix the blur problem in the image I attached (I already tried changing the DPI, which was unsuccessful).

Upvotes: 0

Views: 204

Answers (1)

Mike - SMT
Mike - SMT

Reputation: 15226

There is a DPI setting if you have not tried that part of pyplot.

pyplot.figure(dpi=300)

There is various matplotlib usages options. It is important to note that you will want to use matplotlib.use() function before importing pyplot.

TkAgg, Qt5Agg, Qt4Agg, and GTK3Agg

import matplotlib
matplotlib.use('TkAgg')

There is also MacOSX that should work better with Mac as that is what its designed for.

import matplotlib
matplotlib.use('MacOSX')

In order to use the QT5Agg or QT4Agg you will need to first install the QT library. This will provide python with the bindings to use the QT toolkit.

import tkinter as tk
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt


root = tk.Tk()
fig = plt.figure(dpi=200)
canvas = FigureCanvasTkAgg(fig, root)
canvas.draw()
canvas.get_tk_widget().grid(row=0, column=0, sticky='nsew')

Upvotes: 0

Related Questions