May-23-2020, 12:11 AM
fig = plt.figure() # create figure ax0 = fig.add_subplot(1, 2, 1) # add subplot 1 (1 row, 2 columns, first plot) ax1 = fig.add_subplot(1, 2, 2) # add subplot 2 (1 row, 2 columns, second plot). See tip below** ax2 = fig.add_subplot(2, 2, 3) # add subplot 1 (1 row, 2 columns, first plot) ax3 = fig.add_subplot(2, 2, 4) # add subplot 2 (1 row, 2 columns, second plot). See tip below** # Subplot 1 df_countries.plot(kind='scatter', x='Years', y='Brazil',figsize=(20, 6), ax=ax0) # add to subplot 2 ax0.set_title ('Total Immigration to Canada between 1980 - 2013 from Brazil') ax0.set_ylabel('Number of Immigrants') ax0.set_xlabel('Years') # Subplot 2: df_countries.plot(kind='scatter', x='Years', y='Norway',figsize=(20, 6), ax=ax1) # add to subplot 2 ax1.set_title ('Total Immigration to Canada between 1980 - 2013 from Norway') ax1.set_ylabel('Number of Immigrants') ax1.set_xlabel('Years') # Subplot 3: df_countries.plot(kind='scatter', x='Years', y='Denmark',figsize=(20, 6), ax=ax2) # add to subplot 2 ax2.set_title ('Total Immigration to Canada between 1980 - 2013 from Denmark') ax2.set_ylabel('Number of Immigrants') ax2.set_xlabel('Years') # Subplot 4: df_countries.plot(kind='scatter', x='Years', y='Sweden',figsize=(20, 6), ax=ax3) # add to subplot 2 ax3.set_title ('Total Immigration to Canada between 1980 - 2013 from Sweden') ax3.set_ylabel('Number of Immigrants') ax3.set_xlabel('Years')when I use this code to create subplots the graphs overlay horizontally. Does anybody knows how to make each graph display properly? I generate graphs on Jupiter notebook.