3
$\begingroup$

I need to add two points on a Plot. As they're on the axes, and PlotRange->{{0,27},{0,27}} only half the points are shown. I don't want to increase the PlotRange to include negative values, and I'd rather not have the axes extending below (0,0).

Is there any other option? My code is the following:

Edited full code

Plot[
 {Piecewise[{
    {(5 - .5*q^(1/2))^2, q <= 100/9},
    {(10 - 2*q^(1/2))^2, 100/9 < q < 25}}],
  Piecewise[{
    {(10 - 2*q^(1/2))^2, q <= 100/9},
    {(5 - .5*q^(1/2))^2, 100/9 < q < 30}}],
  25 - q}, {q, 0, 30},
 PlotRange -> {{0, 27}, {0, 27}},
 PlotRangePadding -> .5,
 AspectRatio -> 1,
 Exclusions -> None,
 PlotStyle -> {Black, Directive[Black, Dashed], 
   Directive[Black, Thickness[.005]]},
 Filling -> {1 -> Axis},
 BaseStyle -> {FontFamily -> "Times New Roman", 12},
 AxesStyle -> Directive[Black, Thick],
 Ticks -> None,
 AxesLabel -> {HoldForm[Subscript[q, HoldForm[A]]], 
   HoldForm[Subscript[q, HoldForm[B]]]},
 Epilog -> {
   Text[HoldForm[L] == 50, {8, 25}],
   Text[HoldForm[K] == 50, {22, 8}],
   Text[HoldForm[q] == 25, {5, 22}],
   Text[HoldForm[R], {25, 1}],
   Text[HoldForm[S], {1, 25}],
   PointSize -> .025,
   Point[{{25, 0}, {0, 25}}]

} ]

$\endgroup$
  • 1
    $\begingroup$ Add the option PlotRangePadding -> 0.5 $\endgroup$ – Bob Hanlon Aug 5 '20 at 12:26
  • $\begingroup$ @BobHanlon But with PlotRangePadding the axes go below 0. In this sense, it's equivalent to increase the PlotRange. Isn't it possible to have the axes to start at (0,0) and the points to show entirely? $\endgroup$ – Patricio Aug 5 '20 at 12:55
4
$\begingroup$

Use ImagePadding and PlotRangeClipping:

Plot[
 {Piecewise[{{(5 - .5*q^(1/2))^2, q <= 100/9}, {(10 - 2*q^(1/2))^2, 
     100/9 < q < 25}}], 
  Piecewise[{{(10 - 2*q^(1/2))^2, q <= 100/9}, {(5 - .5*q^(1/2))^2, 
     100/9 < q < 30}}], 25 - q}, {q, 0, 27},
 PlotRange -> {{0, 27}, {0, 27}},
 AspectRatio -> 1,
 Exclusions -> None,
 AxesLabel -> {"x", "y"},
 Filling -> {1 -> Axis},
 Ticks -> None,
 Epilog -> {PointSize -> .025, Point[{{25, 0}, {0, 25}}]},
 ImagePadding -> 20,
 PlotRangeClipping -> False
 ]

enter image description here

This works by first expanding the white-space around the plot area, and then making sure that objects are not clipped at the edge of the plot range. Note that I have change the range for q to go only to 27, so that the lines end where the axis ends (otherwise, the lines will go over the axis label)

$\endgroup$
  • $\begingroup$ But it does clip the AxesLabel (I didn't include them in my original question, sorry). $\endgroup$ – Patricio Aug 5 '20 at 14:04
  • $\begingroup$ You just need to increase the ImagePadding (see edited answer) - note that you can specify different values for different sides if needed. $\endgroup$ – Lukas Lang Aug 5 '20 at 14:43
1
$\begingroup$

You could use ListPlot to plot the points and then combine the two plots using Show.

Show[
 ListPlot[{{25, 0}, {0, 25}}, 
   PlotStyle -> {Black, PointSize[0.025]}, AspectRatio -> 1, Ticks -> None], 
 Plot[{Piecewise[{{(5 - .5*q^(1/2))^2, q <= 100/9}, {(10 - 2*q^(1/2))^2, 100/9 < q < 25}}], 
   Piecewise[{{(10 - 2*q^(1/2))^2, q <= 100/9}, {(5 - .5*q^(1/2))^2, 100/9 < q < 30}}], 25 - q}, {q, 0, 30}, Exclusions -> None, 
   Filling -> {1 -> Axis}]]

enter image description here

$\endgroup$
1
$\begingroup$

If you do not want part of the axes to show, draw them manually:

Plot[{
  Piecewise[{{(5 - .5*q^(1/2))^2, q <= 100/9}, {(10 - 2*q^(1/2))^2, 
     100/9 < q < 25}}],
  Piecewise[{{(10 - 2*q^(1/2))^2, q <= 100/9}, {(5 - .5*q^(1/2))^2, 
     100/9 < q < 30}}], 25 - q}, {q, 0, 30},
 PlotRange -> {{0, 27}, {0, 27}},
 PlotRangePadding -> 0.5,
 AspectRatio -> 1,
 Exclusions -> None,
 Filling -> {1 -> Axis},
 Axes -> None,
 Prolog -> {Lighter[Gray, 0.5], Line[{{0, 27}, {0, 0}, {27, 0}}]},
 Epilog -> {
   PointSize -> .025, Point[{{25, 0}, {0, 25}}]}]

enter image description here

If you are manually adding the axes, you must also manually add the axes labels.

Plot[{Piecewise[{{(5 - .5*q^(1/2))^2, 
     q <= 100/9}, {(10 - 2*q^(1/2))^2, 100/9 < q < 25}}], 
  Piecewise[{{(10 - 2*q^(1/2))^2, q <= 100/9}, {(5 - .5*q^(1/2))^2, 
     100/9 < q < 30}}], 25 - q}, {q, 0, 27}, 
 PlotRange -> {{0, 27}, {0, 27}}, PlotRangePadding -> 2,
 AspectRatio -> 1,
 Exclusions -> None,
 Filling -> {1 -> Axis},
 Axes -> None,
 Prolog -> {
   Text[Style["x", Italic, 12], {27, 0}, {-3, 0}], 
   Text[Style["y", Italic, 12], {0, 27}, {0, -1.5}],
   Lighter[Gray, 0.5],
   Line[{{0, 27}, {0, 0}, {27, 0}}]},
 Epilog -> {PointSize -> .025, Point[{{25, 0}, {0, 25}}]}]

enter image description here

$\endgroup$
  • $\begingroup$ If I set Axes->None then I cannot use AxesLabel $\endgroup$ – Patricio Aug 5 '20 at 13:28
  • 1
    $\begingroup$ As you change or clarify what you are looking for, edit your question to reflect the requirements. People do not want to read through all of the comments to find out what you want. $\endgroup$ – Bob Hanlon Aug 5 '20 at 13:57
  • $\begingroup$ I'm sorry. Just did it. $\endgroup$ – Patricio Aug 5 '20 at 14:14
1
$\begingroup$

I recommend using the AxesOrigin -> {0, 0} option. Like so:

Plot[
  {Piecewise[{{(5 - .5*q^(1/2))^2, q <= 100/9}, {(10 - 2*q^(1/2))^2, 100/9 < q < 25}}], 
   Piecewise[{{(10 - 2*q^(1/2))^2, q <= 100/9}, {(5 - .5*q^(1/2))^2, 100/9 < q < 30}}], 25 - q}, {q, 0, 30}, 
  PlotRange -> {{0, 27}, {0, 27}},
  PlotRangePadding -> Scaled[.02],
  AxesOrigin -> {0, 0},
  AspectRatio -> 1,
  Exclusions -> None,
  Filling -> {1 -> Axis},
  Ticks -> None,
  Epilog -> {PointSize -> .025, Point[{{25, 0}, {0, 25}}]}]

plot

$\endgroup$

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.