简体   繁体   中英

How to plot 5 subplots sharing x and y axes in Python

As in the title, I have 5 plots in Python I want to produce. How would I plot all 5 of these so that they share the same axes? Thanks

You can use subplot with the sharex and sharey options. Example:

import numpy as np
import pylab as pl

x = np.linspace(-1, 1, 100)
y = np.zeros((5, 100))
for i in range(5):
    y[i] = x**i

ax = []    
kw = {}
for i in range(5):
    if i > 0:
        kw ={'sharex': ax[0], 'sharey': ax[0]}
    ax.append(pl.subplot(3, 2, i+1, **kw))
    ax[i].plot(x, y[i])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM