Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selection of the Matplotlib backend using the MPLBACKEND enviro… #135

Closed
wants to merge 3 commits into from

Conversation

jheinen
Copy link
Contributor

@jheinen jheinen commented Jun 11, 2015

This patch allows setting the Matplotlib backend without changing the users' scripts or customizing default options (in .matplotlibrc). This feature is especially useful when mixing (existing) PyPlot calls with functions provided by the GR framework, a universal framework for cross-platform visualization applications.

A similar pull request (for Matplotlib) has already been accepted by the MPL developers. Here you can find a Python example which can easily be ported to Julia, providing enhanced features, especially for real-time visualization.

This is how a Julia example would look like:

import PyCall
@PyCall.pyimport numpy as np

import PyPlot
mpl = PyPlot

import GR

angles = np.load("700K_460.npy")
lens = []

for t in 1:100 
    mpl.cla()
    fig = mpl.subplot(211)
    mpl.ylim([0, 1000])
    mpl.hist(angles[t], 20, normed=0, facecolor="g", alpha=0.5)
    mpl.show()

    lens = [lens, np.size(angles[t])]
    if t > 1
        GR.setwindow(0, 10, 3500, 5000)
        GR.setviewport(0.1, 0.9, 0.05, 0.4)
        GR.axes(1, 0, 0, 3500, 2, 0, 0.005)
        GR.polyline(np.arange(t) / 10.0, lens)
    end

    GR.updatews()
end

@stevengj
Copy link
Member

This is the wrong place to put it — you need to modify the find_backend function so that you initialize the desired backend.

@jheinen
Copy link
Contributor Author

jheinen commented Jun 13, 2015

I understand. I changed the logic in the last commit (0321c0d). The find_backend function is no longer called when the MPLBACKEND environment is set. The user should be able to switch the backend without changing a single line of code. Is this ok?

@stevengj
Copy link
Member

stevengj commented Jul 2, 2015

No, you still need find_backend. For one thing, the MPLBACKEND might not be supported. For another thing, find_backend figures out whether we need to start a GUI event-loop thread for the backend.

Basically, I think you should just alter/extend the default = lowercase(get(rcParams, "backend", "none")) line in find_backend

Question: if you have both MPLBACKEND and a backend specified in your matplotlibrc, which takes precedence?

@stevengj
Copy link
Member

Ah, I see the docs say: Setting this environment variable will override the``backend``parameter in *any*``matplotlibrc``, even if there is a``matplotlibrc``in your current working directory.

@stevengj stevengj closed this in 70ea59b Jul 27, 2015
@stevengj
Copy link
Member

Implemented in 70ea59b

@jheinen
Copy link
Contributor Author

jheinen commented Jul 28, 2015

Checked out PyPlot.jl master branch - works perfect.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants