Help to debug PyCall plotting problem


first time using PyCall and I’m having problems generating plots with the Python package that I’m trying to use, but I’m not sure how to debug it.

The Python package I want to use is called ChiantiPy (GitHub - chianti-atomic/ChiantiPy: ChiantiPy is a python package to calculate the radiative properties of astrophysical plasmas based on the CHIANTI atomic database)

In Python I just do (popPlot generates a figure):

import ChiantiPy.core as ch
import numpy as np
import matplotlib.pyplot as plt

t = 10.**(5.8 + 0.05*np.arange(21.))
fe14 = ch.ion('fe_14', temperature=t, eDensity=1.e+9, em=1.e+27)

In Julia I tried something similar:

using PyCall
ch = pyimport("ChiantiPy.core")
np = pyimport("numpy")
plt = pyimport("matplotlib.pyplot")

t = [10^i for i in 5.8 .+ 0.05 .* range(0.0,20.0,step=1)];
fe14 = ch.ion("fe_14", temperature=t, eDensity=1.e+9, em=1.e+27);

But when I run it, I get first this error about libGL, though I don’t think that is important?

julia> include("test.jl")                                                                                                                                                                                            
 found PyQt5 widgets                                                                                                                                                                                                 
 using PyQt5 widgets                                                                                                                                                                                                 
libGL error: No matching fbConfigs or visuals found                                                                                                                                                                  
libGL error: failed to load driver: swrast

then, a new window is created, where the figure should go, but no figure is shown. If I try to close it, then I get a warning from the system that “This window might be busy and is not responding. [etc]”.

If I close this window and later I try to generate the plot again via popPlot() then julia itself dies:

julia> fe14.popPlot()                                                                                                                                                                                                
The X11 connection broke: I/O error (code 1)                                                                                                                                                                         
XIO:  fatal IO error 22 (Invalid argument) on X server ":0.0"                                                                                                                                                        
      after 483 requests (481 known processed) with 0 events remaining.                                                                                                                                              

Any suggestions on how to get this working properly?


This sounds like PyPlot works but calling matplotlib directly from PyCall aborts · Issue #665 · JuliaPy/PyCall.jl · GitHub

If so, calling PyCall.pygui_start(:qt_pyqt5) before the pyimports could help.

Hi, many thanks, indeed this solves the issue.

I had tried before pygui(:qt_pyqt5) thinking that it was doing the same as what you suggested, but that didn’t fix it.

Many thanks,