Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm plotting results from NDSolve, and I'd like to clip them with their value at the point where the line is clipped. So where the curve ends at the edge of the plot, there would be a number indicating the y-value of the curve at that point.

If that's not possible or too complicated, how can I include the end value of the plot in the legend?

here's my plot command:

    Plot[{
Evaluate[Ca //. {parameters}] //. soln,
Evaluate[Cb //. {parameters}] //. soln,
Evaluate[Cc //. {parameters}] //. soln,
Evaluate[Ci //. {parameters}] //. soln,
Evaluate[Cd //. {parameters}] //. soln,
Evaluate[Ce //. {parameters}] //. soln,
Evaluate[Ch //. {parameters}] //. soln}, {w, 0, 500}, 
PlotRange -> All, 
PlotLegends -> {Subscript[C, methane], Subscript[C, ethane], 
Subscript[C, ethylene], Subscript[C, inerts], Subscript[C, 
benzene], Subscript[C, naphthalene], Subscript[C, hydrogen]}, 
AxesLabel -> {"w", "C"}, AspectRatio -> 0.8, 
PlotLabel -> "molar concentration vs catalyst weight"]
share|improve this question
1  
I think you need to provide more information. Do you want the number inside or outside the plot region? Do you care if it's Framed? Would you be comfortable setting it as a custom Ticks or FrameTicks function? Why not just set it as an Epilog? –  Verbeia Nov 14 '13 at 5:43

1 Answer 1

up vote 2 down vote accepted

It's not entirely clear from your question what you want, but perhaps this will suffice. Since you didn't provide your equations, I'm going to take an example from the documentation

s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1.2}, y, {x, 0, 25}];

Note that the solution is a list of solutions, so to get the numerical value of the solution at a point, you need to extract it from the list it sits in.

y[25] /. s

(* {0.0577224} *)

You can use Epilog to put the value you want in as a text label.

With[{end = First[y[25] /. s]}, 
 Plot[Evaluate[y[x] /. s], {x, 0, 25}, PlotRange -> All, 
  PlotRangePadding -> 0.02, 
  Epilog -> Text[ToString@end, {25, end + 0.1}]]]

This actually chops off some of the number, but you didn't want those significant figures anyway, did you? In any case, you can always finesse this with NumberForm, Style, etc and tweak the position to taste.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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