- 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 extract data from a Matplotlib plot?
To extract data from a plot in matplotlib, we can use get_xdata() and get_ydata() methods.
- Set the figure size and adjust the padding between and around the subplots.
- Create y data points using numpy.
- Plot y data points with color=red and linewidth=5.
- Print a statment for data extraction.
- Use get_xdata() and get_ydata() methods to extract the data from the plot (step 3).
- Print x and y data (Step 5).
- To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y = np.array([1, 3, 2, 5, 2, 3, 1]) curve, = plt.plot(y, c='red', lw=5) print("Extracting data from plot....") xdata = curve.get_xdata() ydata = curve.get_ydata() print("X data points for the plot is: ", xdata) print("Y data points for the plot is: ", ydata) plt.show()
Extracting data from plot.... X data points for the plot is: [0. 1. 2. 3. 4. 5. 6.] Y data points for the plot is: [1 3 2 5 2 3 1]
- How to extract data from a plot created by ggplot2 in R?
- Plot data from a .txt file using matplotlib
- How to plot a line graph from histogram data in Matplotlib?
- Plot data from CSV file with Matplotlib
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to make a 4D plot with Matplotlib using arbitrary data?
- How to plot one single data point in Matplotlib?
- How to a plot stem plot in Matplotlib Python?
- How to plot data from multiple two-column text files with legends in Matplotlib?
- How to extract data from a string with Python Regular Expressions?
- How to remove scientific notation from a Matplotlib log-log plot?
- How to plot a remote image from http url using Matplotlib?
- How to get all the legends from a plot in Matplotlib?
- How to retrieve XY data from a Matplotlib figure?
- How to plot a bar graph in Matplotlib from a Pandas series?