1
$\begingroup$

I'm attempting to put a point onto my Plot but need help with the point sizing and using the Graphics function. I'm not sure I'm going about this correctly, but I have been able to produce the lines that I'm looking for using the Line function inside the epilog option. I'm confused about how Mathematica handles marking up Plots. I also want to call out my intersection of the two lines and need help.

Here is what I'm looking for:

  • Callout point of intersection with the (x,y) value at that point.
  • Adjust the size of the point of intersection
  • Add arrows to indicate the direction of the slope

I need clarification about how Mathematica combines its graphics rendering with its plots. I can use Line to place a line inside my Plot but then using Graphics to add other stuff causes errors. What is the proper way to understand how these are rendered so I can add markup to my Plots?

Here is the code with errors:

Plot[{2.13 + 0.7 (-7.4 + x), 2.13 + 0.9 (-8.9 + x)}, {x, 6, 20}, 
 Epilog -> {
    {Red, Line[{{14.15, 0}, {14.15, 6.855}}]}, 
    {Red, Line[{{6, 6.855}, {14.15, 6.855}}]}, 
    {Blue, Graphics[PointSize[0.1], Point[{14.15, 6.855}]]}}, 
 PlotStyle -> Thick, PlotLabel -> "Supply & Demand", 
 AxesLabel -> {"Bushels", "Price"}, 
 PlotLabels -> {"Demand", "Supply"}]

enter image description here

Here is the working Code:

Plot[{2.13 + 0.7 (-7.4 + x), 2.13 + 0.9 (-8.9 + x)},{x, 6, 20}, 
 Epilog -> {
    {Red, Line[{{14.15, 0}, {14.15, 6.855}}]}, 
    {Red, Line[{{6, 6.855}, {14.15, 6.855}}]},
    {Blue,Point[{14.15,6.855}]}}, 
PlotStyle -> Thick, PlotLabel -> "Supply & Demand", 
 AxesLabel -> {"Bushels", "Price"}, 
 PlotLabels -> {"Demand", "Supply"}]
$\endgroup$
2
  • $\begingroup$ I'm sorry there is an error in my slope calculation for demand. Please don't judge me! $\endgroup$
    – Ziggy
    Commented Nov 13, 2022 at 23:31
  • $\begingroup$ Have the labels been interchanged for "supply" and "demand"? $\endgroup$
    – Syed
    Commented May 16, 2023 at 7:44

2 Answers 2

4
$\begingroup$

Try this:

Show[{
  Plot[{2.13 + 0.7 (-7.4 + x), 2.13 + 0.9 (-8.9 + x)}, {x, 6, 20}, 
   PlotStyle -> Thick, PlotLabel -> "Supply & Demand", 
   AxesLabel -> {"Bushels", "Price"}, 
   PlotLabels -> {"Demand", "Supply"}],
  Graphics[{Red, Line[{{14.15, 0}, {14.15, 6.855}}],  
    Line[{{6, 6.855}, {14.15, 6.855}}], Blue, PointSize[0.03], 
    Point[{14.15, 6.855}]}]
  }]

enter image description here

You can also do it with the Epilog as follows:

Plot[{2.13 + 0.7 (-7.4 + x), 2.13 + 0.9 (-8.9 + x)}, {x, 6, 20}, 
 Epilog -> {{Red, Line[{{14.15, 0}, {14.15, 6.855}}]}, {Red, 
    Line[{{6, 6.855}, {14.15, 6.855}}]},
   {Blue, PointSize[0.05], Point[{14.15, 6.855}]}
   }, PlotStyle -> Thick, PlotLabel -> "Supply & Demand", 
 AxesLabel -> {"Bushels", "Price"}, 
 PlotLabels -> {"Demand", "Supply"}]

Have fun!

$\endgroup$
2
  • $\begingroup$ Ah, so I'm placing my Graphics on top of my plot? In the first example you gave. Then how do I do the arrows? How do I place a coordinate point callout? $\endgroup$
    – Ziggy
    Commented Nov 13, 2022 at 16:18
  • $\begingroup$ You can combine everything wrapping the graphics functions by the Show. Have a look at Arrow. You use it like Line. For the coordinates of the point, try either Callout or Text. Have a look at all these functions in the documentation. They are easy to use. $\endgroup$ Commented Nov 13, 2022 at 16:56
3
$\begingroup$

To make the faulty version work and still use Epilog, replace Graphics[...] with First@Graphics[...]. This is to remove the Head Graphics and makes Epilog happy

Plot[{2.13 + 0.7 (-7.4 + x), 2.13 + 0.9 (-8.9 + x)}, {x, 6, 20},
 Epilog -> {
   {Red, Line[{{14.15, 0}, {14.15, 6.855}}]},
   {Red, Line[{{6, 6.855}, {14.15, 6.855}}]},
   {First@Graphics[{Blue, PointSize[0.03], Point[{14.15, 6.855}]}]}},
 PlotStyle -> Thick, PlotLabel -> "Supply & Demand", 
 AxesLabel -> {"Bushels", "Price"}, 
 PlotLabels -> {"Demand", "Supply"}]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ When this one is compiled it doesn't produce an error but it still doesn't create the point. $\endgroup$
    – Ziggy
    Commented Nov 13, 2022 at 16:22
  • $\begingroup$ @Ziggy There was no mention in the question about compile. I do not know anything about Compile and if it even supports plotting. May be post separate question on Compile not working with Plots? I was just answering your question on how to make Epilog accept Graphics. $\endgroup$
    – Nasser
    Commented Nov 13, 2022 at 16:24
  • $\begingroup$ I'm talking about compiled as in when you hit shift + enter to have Mathematica run the code. This code you wrote compiles without errors inside the Mathematica notebook but still doesn't produce a blue dot. $\endgroup$
    – Ziggy
    Commented Nov 13, 2022 at 16:29
  • $\begingroup$ @Ziggy oh I thought you meant Compile command. The correct term to use is Evaluate and not Compile in Mathematica to mean what you meant as the two terms mean something different. As for the blue point, I was just using your code. You need to move the color inside the Graphics. I've updated the answer. $\endgroup$
    – Nasser
    Commented Nov 13, 2022 at 16:36
  • $\begingroup$ Ahh, okay. Thank you! $\endgroup$
    – Ziggy
    Commented Nov 13, 2022 at 16:37

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.