Plot Vertical SubPlot Line Graph in Python

To plot vertical subplot line graph in python using matplotlib package, use plot() function of matplotlib library.

In this article, I will explain you how to plot vertical subplot line chart in python using matplotlib package.

Installation of Packages

We will need matplotlib packages to create line chart in python. If you don’t have these packages installed on your system, install it using below commands.

pip install matplotlib

Parameters for Customization of Line Plot

using below parameters in plot() function to customized line plot with line style, color and marker.

plot(x, y)        # plot x and y using default line style and color
plot(x, y, 'bo')  # plot x and y using blue circle markers
plot(y)           # plot y using x as index array 0..N-1
plot(y, 'r+')     # ditto, but with red plusses

representation formats for styling
**Markers**

=============    ===============================
character        description
=============    ===============================
``'.'``          point marker
``','``          pixel marker
``'o'``          circle marker
``'v'``          triangle down marker
``'^'``          triangle up marker
``'<'``          triangle left marker
``'>'``          triangle right marker
``'1'``          tri down marker
``'2'``          tri_up marker
``'3'``          tri_left marker
``'4'``          tri_right marker
``'s'``          square marker
``'p'``          pentagon marker
``'*'``          star marker
``'h'``          hexagon1 marker
``'H'``          hexagon2 marker
``'+'``          plus marker
``'x'``          x marker
``'D'``          diamond marker
``'d'``          thin_diamond marker
``'|'``          vline marker
``'_'``          hline marker
=============    ===============================

**Line Styles**

=============    ===============================
character        description
=============    ===============================
``'-'``          solid line style
``'--'``         dashed line style
``'-.'``         dash-dot line style
``':'``          dotted line style
=============    ===============================

Example format strings::

    'b'    # blue markers with default shape
    'or'   # red circles
    '-g'   # green solid line
    '--'   # dashed line with default color
    '^k:'  # black triangle_up markers connected by a dotted line

**Colors**

The supported color abbreviations are the single letter codes

=============    ===============================
character        color
=============    ===============================
``'b'``          blue
``'g'``          green
``'r'``          red
``'c'``          cyan
``'m'``          magenta
``'y'``          yellow
``'k'``          black
``'w'``          white
=============    ===============================
We can use any combination of color, markers and styling to the graph. And make the graph customized the way we want.

How to Plot Vertical Subplot Line Graph in Python

Let’s see an example to plot vertical subplot line chart using matplotlib library

Installation of Packages

We will need matplotlib packages to show line graph. Install packages using below command.

pip install matplotlib

Import libraries

Import matplotlib libraries in our python vertical line graph code to get started with plotting line chart.

# Import library

import matplotlib.pyplot as plt

Cool Tip: Learn How to plot horizontal line graph in python !

Prepare dataset

Create a dataset for x and y axis to plot vertical subplot line chart to display weather forecast for week

  • Prepare dataset of days for x axis
  • Create dataset of temperature for y axis
# Create a dataset of weather forecast to plot vertical subplot line graph

# Create dataset of days for x-axis
days=['Monday','Tuesday','Wednesday','Thursday','Friday']

# Create dataset of temperature for y axis

day_temp=[31,32,32,32,33]
night_temp=[16,15,14,11,12]

Draw Vertical Line subplot using Plot()

Use plt.subplot() function of matplotlib module to draw line graph.

Use matplotlib title to assign subplot1 title

We have used tuple in subplot(). tuple format is (rows, columns, number of plot)

In subplot 1, we have plotted day temperature.

# Plot sublot 1 for day temperature
plt.subplot(1,2,1)
plt.plot(days,day_temp,'cD--')
plt.xticks(rotation=60) 
plt.title('Day Temperature')

In subplot 2, we have plotted night temperature.

# Plot sublot2 for night temperature
plt.subplot(1,2,2)
plt.plot(days,night_temp,'mD--')
plt.xticks(rotation=60)
plt.title('Night Temperature')

Plot Vertical Subplot Line Graph

Use show() function of matplotlib.pyplot module to plot line graph

# Set title
plt.suptitle('Weather Forecast')
plt.show()

Python Vertical Subplot Line Plot Code

Use below entire vertical subplot Line chart in python code using matplotlib library

# Import library
import matplotlib.pyplot as plt

# Create a dataset of weather forecast to plot vertical subplot line graph

# Create dataset of days for x-axis
days=['Monday','Tuesday','Wednesday','Thursday','Friday']

# Create dataset of temperature for y axis

day_temp=[31,32,32,32,33]
night_temp=[16,15,14,11,12]

# Plot sublot 1 for day temperature
plt.subplot(1,2,1)
plt.plot(days,day_temp,'cD--')
plt.xticks(rotation=60) 
plt.title('Day Temperature')

# Plot sublot2 for night temperature
plt.subplot(1,2,2)
plt.plot(days,night_temp,'mD--')
plt.xticks(rotation=60)
plt.title('Night Temperature')

# Set title
plt.suptitle('Weather Forecast')
plt.show()

Vertical Subplot Line Graph Visualization Output

Vertical Subplot Line Graph in Python
Vertical Subplot Line Graph in Python

Conclusion

I hope you found above article on Vertical Subplot Line Graph in Python using matplotlib informative and educational.

Use plt.plot() function of matplotlib module to create vertical subplot line chart.