JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
478 stars 88 forks source link

function `subplots_adjust` does nothing... #303

Closed Datseris closed 7 years ago

Datseris commented 7 years ago
using PyPlot
f = figure(1)

for j in 1:4
  subplot(2,2,j)
  plot(rand(10), rand(10))
end

# these lines do nothing for me, and I cannot understand why.
subplots_adjust(hspace = 0.01)
subplots_adjust(wspace = 0.01)

# maybe because when I see the picture, it looks like `tight_layout()` is on by default
# however, I looked at my matplotlibrc file this is nowhere stated...

Irrespectively of the numbers given to subplots_adjust, nothing happens.

Datseris commented 7 years ago

The function tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0) also has no impact on my figure.

Doing: f[:tight_layout](pad=0.4, w_pad=0.1, h_pad=1.0) also has no impact on my figure.

Doing: f[:subplots_adjust](hspace = 0.01) also does nothing.

stevengj commented 7 years ago

What happens if you try the equivalent code in Python?

Datseris commented 7 years ago

I have no idea actually. I opened spyder but I could not make it work. plt.figure() could not produce a figure for the love of it, even if the console said that an object was created. I've used all the combinations of pylab.show() , draw, etc. and the same from pyplot with show and interactive mode on, but I could not have a figure window appear no matter what.

Since I haven't used Python in over a year and I won't be using it in the future, I did not bother fixing it...

But does what I reported here work for you or not?

stevengj commented 7 years ago

They work fine for me (Julia 0.6, with the Conda.jl Python installation on MacOS), both as inline plots in IJulia and in a qt5agg backend window. Without the subplots_adjust lines, I get: image and with the subplots_adjust lines I get: image So, I'm guessing that this is a problem with Matplotlib on your machine.

When there is a plotting glitch like this, I generally ask people to try it in Python to see whether the problem is in Matplotlib itself or in their Python installation.

stevengj commented 7 years ago

If you don't want to maintain a working Python installation, especially on Windows or Mac, I highly recommend that you let Julia manage its own Python installation via Conda. Do

ENV["PYTHON"]=""
using Conda
Conda.update()
Pkg.build("PyCall")

to make sure that PyCall is configured using Conda and that Conda is up-to-date.

Datseris commented 7 years ago

Thank you. I will do that then. Would you be so kind to tell where does Conda store the matplotlibrc file? I always change the default settings.

stevengj commented 7 years ago

Matplotlib will tell you this: just do PyPlot.matplotlib[:matplotlib_fname]()

stevengj commented 7 years ago

Actually, matplotlib_fname tells you the location of the currently active matplotlibrc. If you haven't installed your own, this will be the one packaged with Conda (in site-packages/matplotlib/mpl-data/matplotlibrc), but you don't want to edit that one because it will get overwritten when Conda is updated. Instead, you want to copy it to $HOME/.matplotlib/matplotlibrc and edit it there, where $HOME is your home directory (homedir() in Julia).

stevengj commented 7 years ago

This is all described in the matplotlib docs: https://matplotlib.org/users/customizing.html#customizing-with-matplotlibrc-files

Datseris commented 7 years ago

Thank you, everything works fine now.

I also finally understood what the problem was!!! In the matplotlibrc file there is some configuration under FIGURE: #figure.autolayout : False which I have set to True making almost every positional change impossible!