Python Forum
Plotting issue Matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plotting issue Matplotlib
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regression plotting + minor issue mohi_gh 0 1,434 Feb-01-2021, 04:19 PM
Last Post: mohi_gh
  matplotlib.pyplot issue lonaveia 2 2,314 Jul-28-2020, 02:40 PM
Last Post: hussainmujtaba
  matplotlib pyplot ginput issue MLiljeroth 0 3,514 Oct-12-2018, 07:12 AM
Last Post: MLiljeroth
  Issue plotting coordinates using Basemap kiton 5 8,230 Mar-09-2017, 07:33 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020