0

What I am trying to do, is visualize data with 3 independent variables. So I made a grid of plots using subplots, where the x axis is the same everywhere. The y axis, on the other hand, depends on the position on the grid. In the x-direction you have another independent variable and the same in the y-direction. So what I would like to do, is to have some kind of overarching axis where the ticks and the numbers are right underneath (for the axis below) each column, so you know which value of this particular variable the column corresponds to. I can't seem to find any info on how to do this with matplotlib. link to sketch

fig,ax=plt.subplots(5,3,sharex='col',sharey='row',figsize=(6,10))
for inrs in range(nrs):
    for inrg in range(nrg):
        n=int(neti[inrs,inrg])
        ax[inrs,inrg].plot(xet[inrs,inrg,1:n],dphid[inrs,inrg,1:n],color='green')

plt.show()
2
  • It would help if you provided the code for what you have so far, and a mockup drawing of the desired final plot Feb 9, 2021 at 21:55
  • The sketch is understandable - thought I think you may want to do it better next time ;) Feb 10, 2021 at 0:11

1 Answer 1

0

I found a way to do this. I don't think there is any "regular" way of doing this. What I did was to use the command
ax=fig.add_axes([0.25,0.05,0.55,0.000001])
for the x axis. Here, (0.25,0.05) is the position (x0,y0), and (0.55,0.000001) is the (width,height) of the figure. The exact numbers depend on the plots you have. What you are doing in essence, is creating an additional very thin plot, where only the x-axis will be visible. To disable the y-axis:
ax.axes.get_yaxis().set_visible(False)
Then you can use the commands:
ax.set_xlabel("xlabel")
ax.set_xlim([])
ax.set_xticks([])
to complete the axis. For the y-axis, it's the same thing. In my case, for the x-axis, the ticks are not evenly spaced. To fix this, I simply created another such plot within the previously existing one to put a particular tick where I needed it to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.