Subplot Syntax

We can create subplots using .subplot().

The command plt.subplot() needs three arguments to be passed into it:

  • The number of rows of subplots
  • The number of columns of subplots
  • The index of the subplot we want to create

For instance, the command plt.subplot(2, 3, 4) would create “Subplot 4” from the figure above.

Any plt.plot() that comes after plt.subplot() will create a line plot in the specified subplot. For instance:

# Data sets x = [1, 2, 3, 4] y = [1, 2, 3, 4] # First Subplot plt.subplot(1, 2, 1) plt.plot(x, y, color='green') plt.title('First Subplot') # Second Subplot plt.subplot(1, 2, 2) plt.plot(x, y, color='steelblue') plt.title('Second Subplot')

Example

months = range(12)
temperature = [363639526172777568574848]
flights_to_hawaii = [12001300110014508507504004504008609901000]

plt.subplot(1,2,1
plt.plot(months,temperature)
plt.subplot(1,2,2
plt.plot(temperatureflights_to_hawaii"o")
plt.show()
# Display both subplots 


plt.subplot(2,1,1)
plt.plot(straight_line,x)
plt.subplot(223)
plt.plot(x,parabola)
plt.subplot(2,2,4)
plt.plot(x,cubic)
plt.subplots_adjust(bottom=0.2wspace=0.35)
plt.show()



AX AND SET XTICKS

plt.xlabel("Months")
plt.ylabel("Conversion")

plt.plot(monthsconversion)

# Your work here
ax = plt.subplot()
ax.set_xticks(months)
ax.set_xticklabels(month_names)
ax.set_yticks([0.100.250.50.75])
ax.set_yticklabels(["10%""25%""50%""75%"])

plt.show()


Comments

Popular posts from this blog

Binomial Test in Python

Slicing and Indexing in Python Pandas

Python Syntax and Functions Part2 (Summary Statistics)