Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Each row sharey individually?

I have a two-by-two plot that I am creating dynamically. In the first row I want to plot density functions, in the second row CDFs. I want

  • each of the columns to share x
  • each of the rows to share y

That is, two objects aligned vertically have the same x-axis, and two plots aligned horizontally have the same y-axis.

However, sharex and sharey force them to be the same for all of the subplots. How can I fix this sort of axes sharing? I understand that I could be manually giving each axes a share partner, but that wouldn't work with the generic structure that follows:

fig, axes = plt.subplots(nrows=2, ncols=2, sharex=True) for i, lam in enumerate(lams):     axesNow = [axs[i] for axs in axes]  # pick the ith column from axes     for i, Param.p in enumerate(pp):         axesNow[0].plot(somethingWithPDF)         axesNow[1].plot(somethingWithCDF)  for ax in axes.flatten(): ax.legend() 

enter image description here

like image 714
FooBar Avatar asked Sep 13 '16 14:09

FooBar


People also ask

What is sharey?

The name Sharey is primarily a female name of American origin that means Darling. form of Cherie.

What is sharey true?

What is sharey true? Controls sharing of properties among x ( sharex ) or y ( sharey ) axes: True or 'all': x- or y-axis will be shared among all subplots. False or 'none': each subplot x- or y-axis will be independent.

What does PLT subplot 1 2 2 mean?

The subplot() Function #the figure has 1 row, 2 columns, and this plot is the first plot. plt.subplot(1, 2, 2) #the figure has 1 row, 2 columns, and this plot is the second plot.


1 Answers

The pyplot.subplots documentation describes the 'col' and 'row' options for the sharex and sharey kwargs. In particular, I think you want:

fig, axes = plt.subplots(nrows=2, ncols=2, sharex='col', sharey='row') 
like image 61
farenorth Avatar answered Oct 09 '22 18:10

farenorth