I have a code:
import matplotlib.pyplot as plt def print_fractures(fractures): xpairs = [] ypairs = [] plt.figure(2) plt.subplot(212) for i in range(len(fractures)): xends = [fractures[i][1][0], fractures[i][2][0]] yends = [fractures[i][1][1], fractures[i][2][1]] xpairs.append(xends) ypairs.append(yends) for xends,yends in zip(xpairs,ypairs): plt.plot(xends, yends, 'b-', alpha=0.4) plt.show() def histogram(spacings): plt.figure(1) plt.subplot(211) plt.hist(spacings, 100) plt.xlabel('Spacing (m)', fontsize=15) plt.ylabel('Frequency (count)', fontsize=15) plt.show() histogram(spacings) print_fractures(fractures)
This code will produce the following result: 
My questions:
1) Why are two separate shapes created? I thought the subplot team would combine them into one shape. I thought it could be a few plt.show () commands, but I tried to comment on them and only call them once from outside my functions, and I still have 2 windows.
2) How can I correctly combine them into 1 figure? In addition, I would like the axes of figure 2 to have the same scale (i.e. 400 m along the x axis would be the same length as 400 m along the y axis). Similarly, I would also like to stretch the histogram vertically - how is this achieved?
python matplotlib plot
Flux capacitor
source share