簡體   English   中英

Matplotlib 圖中的子圖和總標題“圖”

[英]Matplotlib SubPlotpositions in Figure and general heading "figure"

為了繪制數據,我創建了圖。 數字

是否有可能減少子圖之間的水平和垂直距離以及兩個上部子圖和圖形標題之間的垂直距離?

我還想知道為什么右上角 plot 中的 Energy_z 刻度線不會 go 進入繪圖平面(與左上圖中的 Energy_z 刻度線一樣)。 這是什么原因?

我怎樣才能刪除位於人物標題上方的“人物”?

預先感謝您的回答!

    fig = plt.figure(figsize=(50/2.54,40/2.54))
    fig.suptitle(f'Features {list_required_colums[:3]}',fontsize=15)
    
    ax = fig.add_subplot(221, projection='3d')
    ax.scatter(Frame_Datas[list_required_colums[0]] , Frame_Datas[list_required_colums[1]]  ,Frame_Datas[list_required_colums[2]] ,c=Frame_Datas.color_labels, alpha = 0.5, s=15)
    ax.set_xlabel(list_required_colums[0],labelpad=10, fontsize=13)
    ax.set_ylabel(list_required_colums[1],labelpad=10, fontsize=13)
    ax.set_zlabel(list_required_colums[2], labelpad=10,fontsize=13)
    ax.legend(handles=legend_elements, loc='upper right',ncol=1,bbox_to_anchor=(1.0, 0.75))
    ax.set_xticks([])
    ax.tick_params(axis='both', which='major', labelsize=10)
    ax.yaxis._axinfo['tick']['inward_factor'],ax.zaxis._axinfo['tick']['inward_factor'],ax.xaxis._axinfo['tick']['inward_factor']=2,2,2 
    ax.yaxis._axinfo['tick']['outward_factor'],ax.zaxis._axinfo['tick']['outward_factor'],ax.xaxis._axinfo['tick']['outward_factor']=2,2,2
    ax.view_init(0,0)

    ax2 = fig.add_subplot(222, projection='3d')
    ax2.scatter(Frame_Datas[list_required_colums[0]] , Frame_Datas[list_required_colums[1]]  ,Frame_Datas[list_required_colums[2]] , c=Frame_Datas.color_labels, alpha = 0.5, s=15)
    ax2.yaxis._axinfo['tick']['inward_factor'],ax2.zaxis._axinfo['tick']['inward_factor'],ax2.xaxis._axinfo['tick']['inward_factor']=2,0.2,2 
    ax2.yaxis._axinfo['tick']['outward_factor'],ax2.zaxis._axinfo['tick']['outward_factor'],ax2.xaxis._axinfo['tick']['outward_factor']=2,0.2,2
    ax2.set_xlabel(list_required_colums[0],labelpad=10, fontsize=13)
    ax2.set_ylabel(list_required_colums[1],labelpad=10, fontsize=13)
    ax2.set_zlabel(list_required_colums[2],labelpad=10, fontsize=13)
    ax2.legend(handles=legend_elements, loc='upper right',ncol=1,bbox_to_anchor=(0.18, 0.75))      
    ax2.set_yticks([])
    ax2.tick_params(axis='both', which='major', labelsize=10)
    ax2.zaxis._axinfo['juggled'] = (1,2,0)
    ax2.view_init(0,90)

    ax3 = fig.add_subplot(223, projection='3d')
    ax3.scatter(Frame_Datas[list_required_colums[0]] , Frame_Datas[list_required_colums[1]]  ,Frame_Datas[list_required_colums[2]] , c=Frame_Datas.color_labels, alpha = 0.5, s=15)
    ax3.yaxis._axinfo['tick']['inward_factor'],ax3.zaxis._axinfo['tick']['inward_factor'],ax3.xaxis._axinfo['tick']['inward_factor']=0.2,0.2,0.2
    ax3.yaxis._axinfo['tick']['outward_factor'],ax3.zaxis._axinfo['tick']['outward_factor'],ax3.xaxis._axinfo['tick']['outward_factor']=0.2,0.2,0.2
    ax3.set_xlabel(list_required_colums[0],labelpad=10, fontsize=13)
    ax3.set_ylabel(list_required_colums[1],labelpad=10, fontsize=13)
    ax3.set_zlabel(list_required_colums[2],labelpad=10, fontsize=13)
    ax3.legend(handles=legend_elements, loc='upper right',ncol=1)      
    ax3.tick_params(axis='both', which='major', labelsize=10)
    ax3.view_init(30,30)
    
    ax4 = fig.add_subplot(224, projection='3d')
    ax4.scatter(Frame_Datas[list_required_colums[0]] , Frame_Datas[list_required_colums[1]]  ,Frame_Datas[list_required_colums[2]] , c=Frame_Datas.color_labels, alpha = 0.5, s=15)
    ax4.yaxis._axinfo['tick']['inward_factor'],ax4.zaxis._axinfo['tick']['inward_factor'],ax4.xaxis._axinfo['tick']['inward_factor']=0.2,0.2,0.2
    ax4.yaxis._axinfo['tick']['outward_factor'],ax4.zaxis._axinfo['tick']['outward_factor'],ax4.xaxis._axinfo['tick']['outward_factor']=0.2,0.2,0.2
    ax4.set_xlabel(list_required_colums[0],labelpad=10, fontsize=13)
    ax4.set_ylabel(list_required_colums[1],labelpad=10, fontsize=13)
    ax4.set_zlabel(list_required_colums[2],labelpad=10, fontsize=13)
    ax4.legend(handles=legend_elements, loc='upper right',ncol=1)
    ax4.view_init(30,140)
    

你試試像

fig = plt.figure(figsize=(50/2.54,40/2.54))
plt.subplots_adjust(wspace=0.1 , hspace=0.1 )

其中 wspace 是子圖水平方向的空間,hspace 是垂直方向的空間

正如 ymmx 指出的那樣,您可以玩plt.subplots_adjust(wspace=-0.35, hspace=-0.1) 在這里,我設置負值以將子圖組合在一起。 注意:

  1. 過多的負值會使子圖重疊。
  2. 這些值在某種程度上與figsize相關。 如果您更改figsize ,您可能必須將plt.subplots_adjust更改為新值。

關於你的第二個問題,它發生是因為默認情況下 Matplotlib 3D 使用透視相機。 您可以使用ax2 = fig.add_subplot(222, projection='3d', proj_type='ortho')將其更改為正交相機,也可以創建 2D 子圖!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM