I have a graph where on my Y axis , I have price and on X axis I have period/time.

My range on Y axis is from 10 (lower limit) to 200 (upper limit), so to draw the point on graph I need the Y position of the value for example if my price is 100.50 then how should I calculate Y position of this price .


If my upper limit point is (200,HeightOfGraph) that is P1, and the lower limit point is (0,0) is P2, so if height of graph is 100 so if the value is 100 it's y position will be 50 , but how should I calculate it , is there any formula to do this ?

  • $\begingroup$ It isn't very clear what you are trying to achieve, ListPlot plots points at coordinates given by {x,y} pairs. In what way does this not solve your problem ? $\endgroup$ Commented Jul 25, 2012 at 8:58
  • 1
    $\begingroup$ I downvoted provisionally because it is not clear if this has anything to do with Mathematica and if you have tried anything on your own yet. Please see the FAQ and consider changing your question accordingly. $\endgroup$
    – Yves Klett
    Commented Jul 25, 2012 at 9:33
  • $\begingroup$ Seems like you only solve tough problems, thanks anyway. $\endgroup$ Commented Jul 25, 2012 at 9:41
  • 1
    $\begingroup$ It is not about tough problems at all. You simply have a much better chance of quickly getting (usually top-flight) answers from users if you pose a question well. $\endgroup$
    – Yves Klett
    Commented Jul 25, 2012 at 9:46
  • $\begingroup$ Are you talking about finding the y value for a given x coordinate when you have a straight line graph, as in regentsprep.org/regents/math/geometry/GCG1/EqLines.htm $\endgroup$ Commented Jul 25, 2012 at 9:49

4 Answers 4


You can find the y value for a given x coordinate for a straight line by creating an interpolation function in Mathematica of order 1.

For points {0,0} and {200,h} you would do the following.

f = Interpolation[{{0, 0}, {200, h}}, InterpolationOrder -> 1]

Where h is the height of your second point.

You can then find the value of y for any x coordinate using, here for the x value 50:


Mathematica graphics

You can replace h with the value for your application to get a numeric answer, as in:

f2 = Interpolation[{{0, 0}, {200, 100}}, InterpolationOrder -> 1]

Here, for a value of h of 100.



You can plot the values for the function you have created to check that it represents your desired solution:

Plot[f2[x], {x, 0, 200}]

Mathematica graphics


If you have a number of points you use ListPlot with the points' coordinates as a list of arguments. You shouldn't worry about the placing on the graph, that's what Mathematica takes care of. If you want you can change the vertical range by using PlotRange.


tungsten = {{20, 5.5}, {227, 10.5}, {727, 24.3}, {1727, 55.7}, {2727, 90.4}, {3227, 108.5}}  
(* resistivity in microOhm cm at x °C *)
ListPlot[tungsten, PlotRange -> {0, 80}]

If I understand your question correctly (and it isn't entirely clear), then your question is how to plot a line, given two coordinates, one at each end. This is pretty straightforward.

Graphics[Line[{{0, 0}, {200, height}}] /. height -> 100, Axes -> True]

enter image description here

But it seems like you are wanting the equation, so you can work out the intermediate points. The formula I learned in high school was $y = m x + b$, where $m = \frac{rise}{run}$, where $rise$ is the difference between the $y$ coordinates and $run$ is the difference between the $x$ coordinates.

riseoverrun[{x1_, y1_}, {x2_, y2_}] := 
 With[{m = (y2 - y1)/(x2 - x1)}, Flatten@{m, Solve[m x1 + b == y1, b]}]

So you can write:

riseoverrun[{0, 0}, {200, height}]

Which gives:

{height/200, b -> 0}

You can then find the equation:

First@coords x /. height -> 100 + b /. (Last@coords)
(* x/2  *)

Or if you prefer, just put the above in the Plot function:

Plot[First@coords x /. height -> 100 + b /. (Last@coords), {x, 0, 100}]

enter image description here


I think you can get what you want from using simple ratios as follows:

p = (v-v1)/(v2-v1)*(p2-p1) + p1

where: p is the pixel position corresponding to the value v you want, and p1 is the pixel position at the bottom of the y axis corresponding to value 'v1', and p2 is the pixel position at the top of the y axis corresponding to value v2

  • $\begingroup$ Hello @hay, welcome to Mathematica.SE! I fixed up your missing parenthesis and tweaked some formatting. However, you have both p1 and P1 in your answer. Mathematica is case-sensitive. Do you mean for them to be the same? $\endgroup$
    – Verbeia
    Commented Jul 27, 2012 at 3:44
  • $\begingroup$ yes, thanks for the parenthesis, and P1 should be p1. I was a bit sloppy with my answer. I didn't realize mathematica was case-sensitivE. $\endgroup$
    – hay
    Commented Jul 29, 2012 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.