Related parameters in the code
The main object is to use the Add_axes method, note that the coordinates of the three graphs correspond, draw the scatter chart, in the other two sub graphs to draw the corresponding column chart
#!/usr/bin/python #coding: Utf-8 import numpy as NP import Matplotlib.pyplot as Plt plt.style.use ("ggplot") FIG = Plt.f Igure () # Draw the main figure bottom_x_1 = 0.15 Bottom_y_1 = 0.15 width = 0.5 height = 0.5 Rect1 = [Bottom_x_1, bottom_y_1, width, heigh T] ax1 = fig.add_axes (rect1) # Two The coordinate values of the sub graphs need to be noted # draw the topmost child graph, do not need the X axis bottom_x = bottom_x_1 bottom_y = bottom_y_1 + height + 0.0 4 width = width height = 0.2 Rect2 = [Bottom_x, bottom_y, width, height] ax2 = fig.add_axes (rect2, xticks = []) # Draw right child graph, Do not need y-axis bottom_x = bottom_x_1 + width + 0.04 bottom_y = bottom_y_1 width = 0.2 height = 0.5 Rect3 = [bottom_x, bottom_y, width, height] ax3 = fig.add_axes (rect3, yticks = []) # Y with x positive correlation x = Np.random.randn (y = x + np.random.randn (200) * 0.5 Ax1.scatter (x, y) # Sets the width of the histogram to 0.25 bin_width = 0.25 # gets its xy maximum coordinates, and gets the Xymax relative to the origin Xymax = Np.max ([Np.max s (x)), Np.max (Np.fabs (y))] # Set How many blocks can be divided evenly so that Lim can divide Bin_width # plus 1 to avoid rounding effects lim = Int (xymax/bin_width + 1) * Bin _width # Print Lim # set XAxis coordinates Ax1.set_xlim (-lim, lim) bins = Np.arange (-lim, Lim + Bin_width, bin_width) # Draw Columnar Chart ax2.hist (x, bins= bins) ax3.hist (y , bins= bins, orientation = "Horizontal") # Set the figure above and to the right of the diagram corresponding to the main map Ax2.set_xlim (Ax1.get_xlim ()) Ax3.set_ylim (Ax1.get_ylim ()) p Lt.show ()