Plot Xy Graph

Posted onby admin

Complete the following steps to display an array of points on a single-plot XY graph. Add an XY graph to the front panel.; Build a block diagram with the following objects: Divide function; Multiply function; Sine function; Bundle function; For Loop around all objects on the block diagram except the XY graph terminal; Wire the x/y. We will make a Bar-XY chart type, using an XY chart type (a/k/a Scatter chart type) to position markers. Here is the new data needed for our Bar-XY combination chart. The factor labels and Target values will be used by the Bar chart series, and the Actual values and Heights for the XY series.

Combination charts combine data using more than one chart type, for example columns and a line. Building a combination chart in Excel is usually pretty easy. But if one series type is horizontal bars, then combining this with another type can be tricky. I’m here to help with Bar-Line, or rather, Bar-XY combination charts in Excel.

Combination Charts in Excel

I’ll illustrate a simple combination chart with this simple data. The chart will use the first column for horizontal axis category labels, the second column for actual values plotted using lines with markers, and the third column using columns (vertical bars).

We start by selecting the data and inserting a column chart.

We finish by right clicking on the “Actual” data, choosing Change Series Chart Type from the pop-up menu, and selecting the new chart type we want. I’ve also used a lighter shade of orange for the columns, to make the markers stand out better.

Let’s do the same for a bar chart. Select the data, insert a bar chart.

Plot

Okay, the category labels are along the vertical axis, but we’ll continue by changing the Actual data to a line chart series. That didn’t work out at all. The markers are not positioned vertically along the centers of the horizontal bars, nor horizontally where the data lies in the Actual column of the worksheet.

In the chart below I’ve shown all axis scales and axis titles to illustrate the problem. When we converted the Actual series to a line type, Excel assigned it to the secondary axis, and we have no ability to reassign it to the primary axis. The primary axes used for the bar chart are not aligned with the secondary axes used for the line chart: the X axis for the bars is vertical and the X axis for the line is horizontal; the Y axis for the bars is horizontal and the Y axis for the line is vertical.

We can’t use a line chart at all. If we want to line up the markers horizontally with their proper position along the lengths of the bars, we need to use the Actual data as the X values of an XY series. We will need to generate some additional data for the Y values of the XY series.

Bar-XY Combination Chart

We will not try to make a Bar-Line combination chart, because the Line chart type does not position the markers where we want them. We will make a Bar-XY chart type, using an XY chart type (a/k/a Scatter chart type) to position markers.

Here is the new data needed for our Bar-XY combination chart. The factor labels and Target values will be used by the Bar chart series, and the Actual values and Heights for the XY series. Don’t worry about the Height values: I’ll show how they are derived in a moment. The nice thing is that we can use dummy values now and type in the proper values later and the chart will update.

Select the first two columns of the data and insert a bar chart.

Since we probably want the categories listed in the same order as in the worksheet, let’s select the vertical axis (which in a bar chart is the X axis) and press Ctrl+1, the shortcut that opens the Format dialog or task pane for the selected object in Excel. Check the box for Categories in Reverse Order and also select Horizontal Axis Crosses at Maximum Category to move it next to Factor 5.

I’ve also recolored the bars orange, because blue markers show up better against light orange than orange markers against light blue.

Now copy the last two columns (Actual and Height), select the chart, and on the Home tab of the ribbon, click the Paste dropdown arrow, choose the options in this dialog (add cells as new series, values in columns, series names in first row, categories in first column), and click OK.

The data is added as another set of bars, which I’ve colored blue, but we’ll change that in a second.

Right-click on the added series, select Change Series Chart Type from the pop-up menu, and select XY with markers and lines.

How To Plot Xy Graph In Excel

We see that the horizontal positions of the markers is just what we want to show.

Now we can see where the values in the Heights column comes from. The right hand vertical axis is used for the Y values of the XY series. Looking at the positions of the horizontal bars and the markers in their correct positions, we can see that the Factor 1 bar is centered on Y=4.5, the Factor 2 bar is centered on 3.5, etc. If you hadn’t guessed this at the beginning, type these values into your data range, and let the chart update.

A few minor changes and we’ll be done. First, change the name of the XY series from Heights to Actual. The easiest way is to click on the series, then look at the highlighted ranges in the chart. The X values (C2:C6) are highlighted purple, the Y values (D2:D6) are highlighted blue, and the series name (cell D1) is highlighted red (highlight colors in Excel 2010 and earlier are different, but the concept is the same). Click on the red border of cell D2, and drag the highlighting rectangle to cover cell C2 to change the series name.

Click on the red border of cell D2, and drag the highlighting rectangle to cover cell C2 to change the series name.

Then, use a lighter shade of orange for the bars, so the blue markers stand out. Finally, hide the right-hand vertical axis: format it so it has no labels and no line color.

And there’s our completed Bar-XY Combination Chart.

A Scatter (XY) Plot has points that show the relationship between two sets of data.

In this example, each dot shows one person's weight versus their height.

(The data is plotted on the graph as 'Cartesian (x,y) Coordinates')

Example:

The local ice cream shop keeps track of how much ice cream they sell versus the noon temperature on that day. Here are their figures for the last 12 days:

Ice Cream Sales vs Temperature
Temperature °CIce Cream Sales
14.2°$215
16.4° $325
11.9° $185
15.2° $332
18.5° $406
22.1° $522
19.4° $412
25.1° $614
23.4° $544
18.1° $421
22.6° $445
17.2°$408

And here is the same data as a Scatter Plot:

It is now easy to see that warmer weather leads to more sales, but the relationship is not perfect.

Line of Best Fit

We can also draw a 'Line of Best Fit' (also called a 'Trend Line') on our scatter plot:

Try to have the line as close as possible to all points, and as many points above the line as below.

But for better accuracy we can calculate the line using Least Squares Regression and the Least Squares Calculator.

Example: Sea Level Rise

A Scatter Plot of Sea Level Rise:

And here I have drawn on a 'Line of Best Fit'.

Interpolation and Extrapolation

Interpolation is where we find a value inside our set of data points.

Here we use linear interpolation to estimate the sales at 21 °C.

Extrapolation is where we find a value outside our set of data points.

Here we use linear extrapolation to estimate the sales at 29 °C (which is higher than any value we have).

Careful: Extrapolation can give misleading results because we are in 'uncharted territory'.

As well as using a graph (like above) we can create a formula to help us.

Example: Straight Line Equation

We can estimate a straight line equation from two points from the graph above

Let's estimate two points on the line near actual values: (12°, $180) and (25°, $610)

First, find the slope:

slope 'm' = change in ychange in x
= $610 − $18025° − 12°
= $43013°
= 33 (rounded)

Now put the slope and the point (12°, $180) into the 'point-slope' formula:

y − y1 = m(x − x1)

y − 180 = 33(x − 12)

y = 33(x − 12) + 180

y = 33x 396 + 180

y = 33x 216

INTERpolating

Now we can use that equation to interpolate a sales value at 21°:

y = 33×21° 216 = $477

EXTRApolating

And to extrapolate a sales value at 29°:

y = 33×29° 216 = $741

The values are close to what we got on the graph. But that doesn't mean they are more (or less) accurate. They are all just estimates.

Don't use extrapolation too far! What sales would you expect at 0° ?

Plot Xy Graph Matplotlib

y = 33×0° 216 = $216

Hmmm... Minus $216? We extrapolated too far!

Note: we used linear (based on a line) interpolation and extrapolation, but there are many other types, for example we could use polynomials to make curvy lines, etc.

Correlation

When the two sets of data are strongly linked together we say they have a High Correlation.

The word Correlation is made of Co- (meaning 'together'), and Relation

  • Correlation is Positive when the values increase together, and
  • Correlation is Negative when one value decreases as the other increases

Free Online Plotting Tool

Like this:

Make An Xy Graph

(Learn More About Correlation)

Negative Correlation

Plot Xy Graph

Graph

Correlations can be negative, which means there is a correlation but one value goes down as the other value increases.

Example : Birth Rate vs Income

The birth rate tends to be lower in richer countries.

Below is a scatter plot for about 100 different countries.

CountryYearly
Production
per Person
Birth
Rate
Madagascar $800 5.70
India $3,100 2.85
Mexico $9,600 2.49
Taiwan $25,300 1.57
Norway $40,000 1.78

Plot Xy Graph In Labview

It has a negative correlation (the line slopes down)

Plot Xy Graph

Note: I tried to fit a straight line to the data, but maybe a curve would work better, what do you think?