2
$\begingroup$

I am plotting this piecewise function:

$$\rho (x,0) = \rho_{max} \text{ if } x \leq 0 $$ $$\rho (x,0) = 0 \text{ if } x>0. $$

I used this code

Plot[Piecewise[{{pmax, x <= 0}, {0, x > 0}}], {x, -2000, 2000}, 
 Axes -> True, AxesLabel -> {"x", "\[Rho]"}, 
 Ticks -> {{0}, {{2000, "pmax"}}}, PlotStyle -> Thickness[0.01]]

and I get this:

enter image description here

Is it possible to move the tick label $\rho_{max}$ to the right?

$\endgroup$
  • $\begingroup$ Yeah. Look at the examples for Ticks in Plot. $\endgroup$ – b3m2a1 Dec 15 '17 at 2:31
  • $\begingroup$ You have a syntax error (extra comma). $\endgroup$ – David G. Stork Dec 15 '17 at 2:33
  • $\begingroup$ @DavidG.Stork Thanks, but that was a mistake I made copying. My original code was fine. $\endgroup$ – MikelBa Dec 15 '17 at 2:38
  • $\begingroup$ Also... don't you need to specify pmax = 2000? $\endgroup$ – David G. Stork Dec 15 '17 at 2:39
  • $\begingroup$ @DavidG.Stork Sorry, I forgot to copy it because in the nb is separeted somewhere else. $\endgroup$ – MikelBa Dec 15 '17 at 2:42
2
$\begingroup$

I would use Epilog instead of trying to hack the Ticks option to move the tick label to the right:

Plot[
    Piecewise[{{2000, x<=0}, {0, x > 0}}],
    {x, -2000, 2000},
    Axes->True, AxesLabel->{"x","\[Rho]"},
    Ticks->None, Epilog->Text["pmax", Offset[{20, 0}, {0,2000}]],
    PlotStyle->Thickness[0.01]
]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much!!! $\endgroup$ – MikelBa Dec 15 '17 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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