PythonPlot not showing anything

Hi,
I’ve just installed julia 1.12.5 on a new ubuntu box. First thing I tried was to install PythonPlot, and then on the repl

using PythonPlot
plot(rand(1000),randn(1000))

displays nothing at all. In old Pyplot.jl that opened a qt window with the plot, but not here. It just reports that a fiigure has been created but doesn’t show it…

Some installations of Matplotlib (which is under the hood of PythonPlot) do not automatically set interactive mode as one might expect, so you’d have to call PythonPlot.show() or start with PythonPlot.ion() to bring up the window.

PythonPlot should turn on interactive mode by default. What is PythonPlot.backend?

PythonPlot.backend says just “Agg”…

That means that it didn’t find an interactive backend it could use in your matplotlib installation…

On Linux, you can use the following script to install the QT backend for PythonPlot:

#!/bin/bash

# SPDX-FileCopyrightText: 2024 Uwe Fechner
# SPDX-License-Identifier: MIT

# Install matplotlib with Qt backend for PythonPlot using CondaPkg.jl

echo "Installing matplotlib with Qt backend using CondaPkg.jl..."

julia --project -e '
    using Pkg
    
    # Check if CondaPkg.jl is installed, install if needed
    if !haskey(Pkg.project().dependencies, "CondaPkg")
        println("Installing CondaPkg.jl...")
        Pkg.add("CondaPkg")
    end
    
    using CondaPkg
    
    # Install matplotlib and PyQt5
    println("Adding matplotlib and pyqt to CondaPkg...")
    CondaPkg.add("matplotlib")
    CondaPkg.add("pyqt")
    
    # Resolve and install
    println("Resolving and installing packages...")
    CondaPkg.resolve()
    
    println("")
    println("Installation complete!")
    println("To use the Qt backend in Julia, set the backend before plotting:")
    println("  export MPLBACKEND=Qt5Agg; julia --project")

'

This might also work on Windows if you use Bash for Windows.

Disclaimer: Written by AI, hand-corrected and tested by myself.