Logout on Mac when using PyPlot (v1.2)

Hi there,

I just updated to v1.2 and run the code

using PyPlot
plot([i for i = 1:20],[i^2 for i = 1:20])

And my Apple computer (Mojave, 2017) will log me out and close all my windows. Is there a crowd favorite plotting alternative that I could use as a temporary alternative in Julia?

In my computer, not Apple, is working nicely.
However, good alternatives are Vegalite or Gadfly (and others). Try them.

By the way:

using PyPlot
plot(1:20, (1:20).^2)

is a simpler way to write it. Or using variables:

using PyPlot
x=1:20
plot(x, x.^2) 

I’m seeing the same issue on both 1.1 and 1.2. This wasn’t a problem for me just a week ago. The only thing I can think of that I changed in the interim was updating macOS (a point update from 10.14.[4 or 5] to 10.14.6). I tried updating to Julia 1.2 but that didn’t fix the issue. If I plot within vscode rather than from a terminal REPL then it works fine. Pulling up figure windows from pyplot in python also works fine.

I think It is the backend - one needs to change it. I’m afraid I don’t remember what i changed it to. (A mac specific one I think) I can look it up when I’m back at a desktop.

I have a Mac running Mojave (10.14.5), and it works fine for me.

You can try doing

pkg> add Conda
julia> using Conda
julia> Conda.update()

in case something is broken or out of date with your Anaconda installation. (Then relaunch Julia and try PyPlot again.)

(Though honestly it is concerning to me that any problem could cause MacOS to log you out. I’ve never heard of anything like that.)

For the Record - this happened to me with a clean Ansconda installation just 2-3 weeks ago. I am fairly certain it was caused by the default backend.

I should add that this also happens with pure python. The backend 'backend': 'TkAgg' leads to this crash. I just double-checked and confirmed this. In Python, I switch to the MacOSX backend,

import matplotlib.pyplot as plt
plt.switch_backend('MacOSX')

after which matplotlib plotting works fine without any issues.

EDIT: following the Readme at PyPlot.jl, the following works from Julia:

using PyCall
pygui(:qt5)
using PyPlot
x = range(0,1,length=100);
y = cos.(x);
plot(x,y)

But for practical purposes probably best to fix this in the matplotlibrc file : in ~/.matplotlib/matplotlibrc just add the following line:

backend: qt5agg

https://github.com/matplotlib/matplotlib/issues/14999

The tkagg backend is known to be broken in MacOS (TkAgg backend on macOS aborts · Issue #410 · JuliaPy/PyPlot.jl · GitHub) — this a known problem in Matplotlib (Python with the 'TkAgg' backend on macOS crashes out when figure windows are moved · Issue #7743 · matplotlib/matplotlib · GitHub) and is reportedly due to an upstream bug in the tkinter library (Tk Toolkit / Read-Only Bugs / #3082 Crash on MoutainLion with negative offset to wm geometry).

As a result, back in April 2019 I changed PyPlot to not use tkagg by default anymore on MacOS (don't default to tk on macos (closes #410) · JuliaPy/PyPlot.jl@6bd7b68 · GitHub). So the only reason this would show up anymore is if you are explicitly requesting tkagg (either in your .matplotlibrc file or via the MPLBACKEND environment variable).

It is not necessary to change your .matplotlibrc file unless you were explicitly setting the backend to tkagg, which is not common.

It is possible but I don’t remember ever setting this to tkagg - I had assumed that the fresh anaconda install modified this setting. What I know for certain is that before the anaconda install PyPlot worked fine on my system.