This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig, ax = plt.subplots(nrows=1, ncols=2) | |
print(ax) | |
print(type(ax)) | |
___________________ | |
[<AxesSubplot:> <AxesSubplot:>] | |
<class 'numpy.ndarray'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unpacking method | |
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5)) | |
fig.tight_layout(pad=3) | |
ax1.plot(climate_change['date'], climate_change['co2']) | |
ax2.plot(climate_change['date'], climate_change['relative_temp']) | |
plt.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Indexing method | |
fig, ax = plt.subplots(1, 2, figsize=(10, 5)) | |
fig.tight_layout(pad=3) | |
ax[0].plot(climate_change['date'], climate_change['co2']) | |
ax[1].plot(climate_change['date'], climate_change['relative_temp']) | |
plt.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unpacking method | |
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(10, 5)) | |
# ..... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Indexing method | |
fig, ax = plt.subplots(2, 2, figsize=(10, 5)) | |
# ax[0, 0].plot(___) | |
# ax[1, 1].plot(___) | |
ax.shape | |
_____________ | |
(2, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Additional method if you don't want to use double indexes | |
fig, ax = plt.subplots(3, 2) | |
ax.flat[0].plot(climate_change['co2']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting title, labels, etc. | |
fig, ax = plt.subplots() | |
ax.bar(medals.index, medals['Gold']) | |
ax.set(title='# gold medals by country', ylabel='# of medals', xlabel='Country') | |
ax.set_xticklabels(medals.index, rotation=90) | |
plt.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig, ax = plt.subplots() | |
ax.bar(medals.index, medals['Gold']) | |
ax.set_xticklabels(medals.index, rotation=90) | |
ax.set_xlabel('Country', fontsize=15) | |
ax.set_title("# gold medals by country", fontsize=20) | |
plt.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a figure and an axis | |
fig, ax = plt.subplots() | |
# Plot CO2 emissions with a blue line | |
ax.plot(climate_change['date'], climate_change['co2'], color='blue') | |
# Specify that we will be using a twin x axis | |
ax2 = ax.twinx() | |
ax2.plot(climate_change['date'], climate_change['relative_temp'], color='red') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a figure and an axis | |
fig, ax = plt.subplots() | |
# Plot CO2 emissions with a blue line | |
ax.plot(climate_change['date'], climate_change['co2'], color='blue') | |
# Specify that we will be using a twin x axis | |
ax2 = ax.twinx() | |
ax2.plot(climate_change['date'], climate_change['relative_temp'], color='red') |