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

1 Answer 1

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$
1
  • $\begingroup$ Thank you very much!!! $\endgroup$
    – MikelBa
    Dec 15, 2017 at 2:49

Your Answer

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

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