3

As the title suggests, I'd like to make a plot in Pyplot.jl with equal (circles look like circles) and shared (plots have same limits) axes.

I get errors whenever I try to use setp() as in new pythonic style for shared axes square subplots in matplotlib? or use the subplots() command and access the figure and axis elements that are returned. I am also not very familiar with PyPlot or Python in general.

As an example, I'd like to have

using PyPlot

u = linspace(0, 2pi, 100)
unit_x = cos(u)
unit_y = sin(u)

A = [1 2; 0 2]
transf = [unit_x unit_y] * A'

subplot(121)
plot(unit_x, unit_y)
axis(:equal)

subplot(122)
plot(transf[:, 1], transf[:, 2])
axis(:equal)

display plots side-by-side with the same axes so that they are directly comparable. Right now this gives

https://i.stack.imgur.com/RZx2G.jpg

I have also tried returning the axis limits and setting the left plot to equal the right, but they are not returned correctly after calling axis(:equal).

Community
  • 1
  • 1
John Best
  • 33
  • 4

1 Answers1

3

Are you maybe looking for

fig, ax = subplots(1,2, sharey = true)
ax[1,1][:plot](unit_x, unit_y)
ax[2,1][:plot](transf[:, 1], transf[:, 2])

I always tend to think the fig/ax notation is more helpful for doing subplots, but YMMV... This gives:

enter image description here

Nils Gudat
  • 13,222
  • 3
  • 39
  • 60
  • 1
    Thanks! This got me most of the way there. I mostly couldn't figure out the syntax for the `fig`/ `ax` notation. On Julia 0.3.11 with PyPlot 2.1.0 and PyCall 1.0.3, I got an error using two indices for the axes, so I used `ax[1]` and `ax[2]`. An `axis(:equal)` call at the end resized everything appropriately. – John Best Sep 27 '15 at 18:16
  • How can you add a title to the individual subplots? Writing `ax[1,1][:title]("Example...")` doesn't work. – Axion004 Mar 31 '23 at 19:19