TransWikia.com

Problem with Filling Style

Mathematica Asked by lin zang on January 5, 2021

I got two functions and want to plot them using different plotstyle so they can be shown distinctively after printing with black ink. I also need to fill the region between them and label the two regions. I prefer to use Dot or Hatched Filling but don’t know how to do it.
Here is my code:

ifun = Interpolation[{{14.800000000000011`, 
0.3001`}, {15.750000000000025`, 0.2501`}, {16.650000000000038`, 
0.2001`}, {17.60000000000005`, 0.1501`}, {19.300000000000075`, 
0.10010000000000001`}, {20.35000000000009`, 
0.1501`}, {20.700000000000095`, 0.2001`}, {20.9500000000001`, 
0.2501`}, {21.1000000000001`, 0.3001`}, {21.250000000000103`, 
0.35009999999999997`}, {21.350000000000104`, 
0.40009999999999996`}, {21.450000000000106`, 
0.45009999999999994`}, {21.550000000000107`, 
0.5001`}, {21.65000000000011`, 0.5501`}, {21.70000000000011`, 
0.6001000000000001`}, {21.75000000000011`, 
0.6501000000000001`}, {21.80000000000011`, 
0.7001000000000002`}, {21.900000000000112`, 
0.7501000000000002`}, {21.950000000000113`, 0.8001000000000003`}}]
f[x_] := 0.3001 /; 14 < x < 14.8
f[x_] := ifun[x] /; 14.8 < x < 21.95
f[x_] := 0.9001 /; 21.95 < x < 24.95
g[x_] := 0.9001 /; 14 < x < 21.95
Plot[{g[X], f[x]}, {x, 14, 24.95}, 
 Filling -> {1 -> {2}, 2 -> Axis}, PlotLabel -> Profit, 
 AxesLabel -> {"c", "Phi"}, 
 PlotLegends -> 
  SwatchLegend[{"TS", "ST"}, LegendLabel -> "Label", 
   LegendFunction -> (Framed[#, Background -> White] &)]]

Thank you very much!

One Answer

 Plot[{g[x], f[x]}, {x, 14, 24.95}, 
  PlotTheme -> {"Monochrome", "ThickLines"},
  Filling -> {1 -> {{2}, HatchFilling[45 Degree]}, 
    2 -> {Axis, HatchFilling[-45 Degree]}}, 
  PlotLabel -> "Profit",
  AxesLabel -> {"c", "Phi"}, 
  PlotLegends -> SwatchLegend[{HatchFilling[45 Degree], HatchFilling[-45 Degree]}, 
     {"TS", "ST"}, LegendLabel -> "Label", 
     LegendFunction -> (Framed[#, Background -> White] &), 
     LegendMarkerSize -> 20]]

enter image description here

Correct answer by kglr on January 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP