
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to show a bar and line graph on the same plot in Matplotlib?
To show a bar and line graph on the same plot in matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.
Create a figure and a set of subplots.
Plot the bar and line with the dataframe obtained from Step 2.
To display the figure, use show() method.
Example
import pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(data=[2, 4, 1, 5, 9, 6, 0, 7])) fig, ax = plt.subplots() df['data'].plot(kind='bar', color='red') df['data'].plot(kind='line', marker='*', color='black', ms=10) plt.show()
Output
- Related Questions & Answers
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to plot a bar graph in Matplotlib from a Pandas series?
- How to plot a line graph from histogram data in Matplotlib?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to plot two violin plot series on the same graph using Seaborn?
- How to show tick labels on top of a matplotlib plot?
- How to show (0,0) on matplotlib graph at the bottom left corner?
- How to write text above the bars on a bar plot (Python Matplotlib)?
- Show decimal places and scientific notation on the axis of a Matplotlib plot
- How to plot a dashed line on a Seaborn lineplot in Matplotlib?
- Matplotlib – How to show the count values on the top of a bar in a countplot?
- How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- Python - How to plot a Pandas DataFrame in a Bar Graph
- How to animate a line plot in Matplotlib?
Advertisements