# Extracting data from a Plot

• Mathematica
• Swamp Thing
In summary, the conversation discusses a method for extracting data from a Plot in Mathematica using the Cases function. The code uses a pattern to match a Line with x,y coordinates and then uses the :> operator to strip off the Line wrapper. The last two arguments control the levelspec and number of patterns to match. The conversation also speculates on how someone may have come up with this code, by using the InputForm function to view the data and manipulating the levelspec and pattern matching.

#### Swamp Thing

https://mathematica.stackexchange.com/questions/19859/plot-extract-data-to-a-file
... says you can extract the data from a Plot by doing this:
Code:
data = Cases[Plot[Sin@x, {x, 0, 2 Pi}], Line[data_] :> data, -4, 1][[1]];

Having looked at the doc page on Cases, I can't figure out how this works. (And I can't imagine how someone would come up with this, using only the documentation).

I find that changing the last two arguments (-4 and 1) doesn't affect the result, as long as the third one is negative.

So what is going on in that code?

To try to imagine how someone would come up with this, look at

InputForm[Plot[Sin@x,{x,0,2Pi}]]

InputForm presents the data it is given into a less "pretty printed" version that you can look at and use.

When you look at that you should see there are some bits adjusting the appearance and then there is a Line with a vast number of x,y coordinates. And that is followed by more bits adjusting the appearance.

Cases takes an expression and tries to find a matching pattern in it. So in this case it is looking for that Line[...]

Next the :> is doing a substitution. Really all that is doing is stripping off the Line that is wrapped around the points.

And then the last two numbers look like they are choosing the levelspec and the number of patterns to match.

If you try to compare this description to what you see from the InputForm you can see it is trying to control the extraction of the data points that would default to be turned your graph on the screen.

Does this give you an idea how to think about that code?

Swamp Thing

## What is the purpose of extracting data from a plot?

The purpose of extracting data from a plot is to better understand and analyze the information presented in the plot. By extracting the data, it can be manipulated and used in different ways to gain insights and make informed decisions.

## What methods can be used to extract data from a plot?

There are several methods that can be used to extract data from a plot, such as using a ruler and measuring the data points, using a digital protractor to measure angles, using a graphing software to export the data, or manually entering the data into a spreadsheet.

## Can data be extracted from any type of plot?

Yes, data can be extracted from any type of plot as long as the plot has numerical data points. This includes line graphs, bar graphs, scatter plots, pie charts, and more.

## What are some common mistakes when extracting data from a plot?

Some common mistakes when extracting data from a plot include misreading data points, skipping data points, not accounting for decimal places, and not using the correct scale. It is important to carefully and accurately extract the data to ensure reliable results.

## How can extracted data be used in Pampered Chef products?

Extracted data from a plot can be used in Pampered Chef products in various ways. For example, it can be used to track sales and customer preferences, analyze trends and patterns, and make data-driven decisions for product development and marketing strategies.