- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 label bubble chart/scatter plot with column from Pandas dataframe?
To label bubble charts/scatter plot with column from Pandas dataframe, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Create a scatter plot with df.
- Annotate each data point with a text.
- To display the figure, use show() method.
import pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a dataframe df = pd.DataFrame( dict( x=[1, 3, 2, 4, 5], y=[0, 3, 1, 2, 5], points=['Kiran', 'Raju', 'Raja', 'Javed', 'Rishi'] ) ) # Scatter plot ax = df.plot.scatter(x='x', y='y', alpha=0.5) # Annotate each data point for i, txt in enumerate(df.points): ax.annotate(txt, (df.x.iat[i]+0.05, df.y.iat[i])) plt.show()
It will produce the following output
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- Python - Draw a Scatter Plot for a Pandas DataFrame
- How to improve the label placement for Matplotlib scatter chart?
- How to plot a Pandas Dataframe with Matplotlib?
- How to delete a column from Pandas DataFrame
- How to delete a column from a Pandas DataFrame?
- How to add column from another DataFrame in Pandas?
- Create a Scatter Plot with SeaBorn – Python Pandas
- Plot multiple columns of Pandas dataframe on the bar chart in Matplotlib
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- Python Pandas - How to select rows from a DataFrame by passing row label
- Python - How to select a column from a Pandas DataFrame
- How to plot aggregated by date pandas dataframe?
- Merge Pandas DataFrame with a common column
- Annotating points from a Pandas Dataframe in Matplotlib plot