X Plotted Against Y

X Plotted Against Y Rating: 3,1/5 7382 reviews
  1. A straight line on a semilog graph of y versus x represents an exponential function of the form y = a e b x.; A straight line on a log-log graph of y versus x represents a power law function of the form y = a x b. To find the constants a and b, we can substitute two widely-spaced points which lie on the line into the appropriate equation.This gives two equations for the two unknowns a.
  2. We can see even more detail for small values of x and y now, however we can't include the negative temperatures on the horizontal axis. Example 4: Variable Raised to a Fractional Exponent. Graph y = x 1/2 using all 4 axis types (rectangular, both types of semi-log, and log-log). This function is equivalent to `y=sqrt(x)`.
  1. Plot X Against Y Excel
  2. X Plotted Against Yahoo

I am fond of saying that, by themselves, numbers are meaningless. This may be overexaggeration, but the point is that they rarely tell the full story. Data visualization is key to forming insights.

Scatter plots are a basic analytical tool to evaluate possible relationships among variables through visual means.

Wolfram Community forum discussion about Plot a simple x vs. Y plot from a table. Stay on top of important topics and build connections by joining Wolfram Community groups relevant to your interests.

Let’s plot price against carat size (i.e., price on the y-axis and carat on the x-axis). Scatter plots are requested in SAS with a SCATTER statment in a PROC SGPLOT. SG stands for “Statistical Graphics”.

Note: you need to use ODS graphics with PROC SGPLOT.

The PROC explained:

  1. We use the SCATTER statement, assigning carat to the x-axis and price to the y-axis. The x and y arguments are required. You can switch their order, however.
  2. We use the global title statement. Because it’s global, we can move outside of the PROC if we wanted.

Observations:

  1. It appears that as carat size increases, the price of the diamond increases.
  2. It also appears that this relationship is somewhat non-linear. A linear relationship is one that follows a straight line.
  3. Because there are so many observations (over 50k), the visualization suffers from over-plotting. This means that points are so stacked on top of one another that it is difficult to understand the density of data.
  • Matlab Tutorial
  • MATLAB Advanced
  • MATLAB Useful Resources
  • Selected Reading

Plotted

To plot the graph of a function, you need to take the following steps −

  • Define x, by specifying the range of values for the variable x, for which the function is to be plotted

  • Define the function, y = f(x)

  • Call the plot command, as plot(x, y)

Following example would demonstrate the concept. Let us plot the simple function y = x for the range of values for x from 0 to 100, with an increment of 5.

Create a script file and type the following code −

When you run the file, MATLAB displays the following plot −

Let us take one more example to plot the function y = x2. In this example, we will draw two graphs with the same function, but in second time, we will reduce the value of increment. Please note that as we decrease the increment, the graph becomes smoother.

Create a script file and type the following code −

When you run the file, MATLAB displays the following plot −

Change the code file a little, reduce the increment to 5 −

MATLAB draws a smoother graph −

Adding Title, Labels, Grid Lines and Scaling on the Graph

MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to spruce up the graph.

  • The xlabel and ylabel commands generate labels along x-axis and y-axis.

  • The title command allows you to put a title on the graph.

  • The grid on command allows you to put the grid lines on the graph.

  • The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.

  • The axis square command generates a square plot.

Example

Create a script file and type the following code −

MATLAB generates the following graph −

Drawing Multiple Functions on the Same Graph

You can draw multiple graphs on the same plot. The following example demonstrates the concept −

X Plotted Against Y

Example

Create a script file and type the following code −

MATLAB generates the following graph −

Setting Colors on Graph

MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their codes −

CodeColor
wWhite
kBlack
bBlue
rRed
cCyan
gGreen
mMagenta
yYellow

Example

Let us draw the graph of two polynomials

  • f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and

  • g(x) = 5x3 + 9x + 2

Create a script file and type the following code −

When you run the file, MATLAB generates the following graph −

Setting Axis Scales

The axis command allows you to set the axis scales. You can provide minimum and maximum values for x and y axes using the axis command in the following way −

The following example shows this −

Example

Create a script file and type the following code −

When you run the file, MATLAB generates the following graph −

Generating Sub-Plots

When you create an array of plots in the same figure, each of these plots is called a subplot. The subplot command is used for creating subplots.

Syntax for the command is −

where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular plot.

Each plot created with the subplot command can have its own characteristics. Following example demonstrates the concept −

Example

Let us generate two plots −

y = e−1.5xsin(10x)

y = e−2xsin(10x)

Plot X Against Y Excel

Create a script file and type the following code −

X Plotted Against Yahoo

When you run the file, MATLAB generates the following graph −