X Plotted Against Y

 admin

Y x is plotted against x a straight line is obtained, as shown in the graph. The line passes through the points (1, 3) and (3, –1). (i) Express y in terms of x. 4 (ii) Find the value of x and of y such that y x = – 9. 2 8 The table above shows experimental values of the variables x and y which are related by an equation of. Two variables, x and y, are such that y, where and b are constants When Iny is plotted against Inx. A straight line graph is Obtained which passes through the points ( 1.4.5.8) and (2.2.6.0). (i) Find the value of and of b Calculate the value of y when x S 12 The line —y 1 O meets x: 19 at the points A and The.

  1. Plot X Vs Y Graph In Excel
  2. X Plotted Against Youtube
  3. Plot X Against Y Python
  4. X And Y Graph
  5. Plot X Against Y Matlab

Basic Usage – pyplot.plot

Simple use of matplotlib is straightforward:

If you run this code in the interactive Python interpreter, you should get a plot like this:

Two things to note from this plot:

  • pyplot.plot assumed our single data list to be the y-values;

  • in the absence of an x-values list, [0, 1, 2, 3] was used instead.

    Note

    pyplot is commonly used abbreviated as plt, just as numpy is commonlyabbreviated as np. The remainder of this chapter uses the abbreviatedform.

    Note

    Enhanced interactive python interpreters such as IPython can automatesome of the plotting calls for you. For instance, you can run%matplotlib in IPython, after which you no longer need to runplt.show everytime when calling plt.plot.For simplicity, plt.show will also be left out of the remainderof these examples.

If you pass two lists to plt.plot you then explicitly set the x values:

Understandably, if you provide two lists their lengths must match:

To plot multiple curves simply call plt.plot with as many xy listpairs as needed:

Alternaltively, more plots may be added by repeatedly callingplt.plot. The following code snippet produces the same plot as theprevious code example:

Adding information to the plot axes is straightforward to do:

Also, adding an legend is rather simple:

And adjusting axis ranges can be done by calling plt.xlim and plt.ylimwith the lower and higher limits for the respective axes.

In addition to x and y data lists, plt.plot can also take stringsthat define the plotting style:

The style strings, one per xy pair, specify color and shape: ‘rx’ standsfor red crosses, and ‘b-.’ stands for blue dash-point line. Check thedocumentationof pyplot.plot for the list of colors and shapes.

Finally, plt.plot can also, conveniently, take numpy arrays as its arguments.

  • Matlab Tutorial
  • MATLAB Advanced
  • MATLAB Useful Resources
  • Selected Reading

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.

Plot X Vs Y Graph In Excel

  • 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 −

Example

Create a script file and type the following code −

MATLAB generates the following graph −

Setting Colors on Graph

X Plotted Against Youtube

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

Excel

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

Plot X Against Y Python

Let us generate two plots −

y = e−1.5xsin(10x)

X And Y Graph

y = e−2xsin(10x)

Create a script file and type the following code −

Plot X Against Y Matlab

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