2017-02-04 55 views
0

我想有一套小區分成三行,第一行有一個小區,第二行兩個,第三行三個。我做了以下內容:Matplotlib:如何獲得子圖的三角矩陣?

fig, axes = plt.subplots(figsize=(10, 10), sharex=True, sharey=True, ncols=3, nrows=3) 
x = np.linspace(0, 10, 100) 
for i in range(3): 
    for j in range(0, i+1): 
     axes[i, j].plot(x, np.sin((i+j) *x)) 

因此我得到: enter image description here

我怎樣才能去掉三個空地塊?

回答

3

這個怎麼樣?

fig, axes = plt.subplots(figsize=(10, 10), sharex=True, sharey=True, ncols=3, nrows=3) 
x = np.linspace(0, 10, 100) 
for i in range(3): 
    for j in range(3): 
     if i<j: 
      axes[i, j].axis('off') 
     else: 
      axes[i, j].plot(x, np.sin((i+j) *x)) 

它似乎產生你正在尋找一個情節:

enter image description here

+0

你知道如何回到頂部軸xticks? – Ger

+0

@更好,如果你禁用'sharex = True',你會得到所有的xticks標籤。否則,您可以使用單個軸實例的'set_ticklabels'方法。 –