2
$\begingroup$

I have three questions about the following code:

Plot[{1/2 - 3/2 \[Lambda], Min[1/2 - 3/2 \[Lambda], Sqrt[\[Lambda]]]}, {\[Lambda], 0, 1/9}, AxesLabel -> {\[Lambda], \[Gamma]}, PlotStyle -> Black, Filling -> {1 -> {{2}, White}, 2 -> {Axis, Red}},  AxesStyle -> {Directive[Black], Directive[Blue]}, Epilog -> {Text[Style["FULLY ATTRACTIVE", 36], Scaled[{0.6, 0.25}]], Red}]

Mathematica graphics

  1. How can I plot a series of given points on the plot obtained by code shown? For example suppose I have the following series of points:

    {{0.000297159,0.029389}, {0.00114653,0.0566384}, {0.00249252,0.082004},{0.00428816,0.105703} (* etc. *)}
    
  2. Is there a more effective way to write the text "FULLY ATTRACTIVE" in the red region of the plot?

  3. How can I change the axes dimension?

Thanks.

$\endgroup$

1 Answer 1

7
$\begingroup$

First thing let's plot the points

points = {{0.000297159, 0.029389}, {0.00114653, 
    0.0566384}, {0.00249252, 0.082004}, {0.00428816, 0.105703}(*etc.*)};

For that you can keep using Epilog while paying attention to make all its content a valid Graphics element:

plot = Plot[{1/2 - 3/2 \[Lambda], 
  Min[1/2 - 3/2 \[Lambda], Sqrt[\[Lambda]]]}, {\[Lambda], 0, 1/9}, 
 AxesLabel -> {\[Lambda], \[Gamma]}, PlotStyle -> Black, 
 Filling -> {1 -> {{2}, White}, 2 -> {Axis, Red}}, 
 AxesStyle -> {Directive[Black], Directive[Blue]}, 
 Epilog -> {Orange, PointSize[.02], Point[points]}]

The result is

plot_with_points

Your text can be fit into the red shape by making it a little smaller, but let's assume you don't want to manually find the good fit. A possibility is to use WordCloud to find a good layout for you (with the caveat that it's not preserving the ordering of the words, so this method is not valid in general for multi-words labels).

We need to define the appropriate mask:

mask = Binarize[
  Plot[{1/2 - 3/2 \[Lambda], 
    Min[1/2 - 3/2 \[Lambda], Sqrt[\[Lambda]]]}, {\[Lambda], 0, 1/9}, 
   AxesLabel -> {\[Lambda], \[Gamma]}, PlotStyle -> Black, 
   TicksStyle -> Transparent, AxesStyle -> Black, 
   Filling -> {2 -> {Axis, White}}, Background -> Black]]

text_mask

Now we can compute the layout (Erosion is used to leave a little margin)

text = WordCloud["FULLY ATTRACTIVE", Erosion[mask, 5], 
  ColorFunction -> Black];

and use Overlay to compose it with the original plot without worrying too much about the coordinates

Overlay[{plot, text}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you Batracos! $\endgroup$
    – Michaels
    Jul 13, 2017 at 18:48
  • 2
    $\begingroup$ +1. Nice application of WordCloud! $\endgroup$ Sep 12, 2017 at 6: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.