How to shade a plot in Mathematica

好久不见. 提交于 2019-12-07 08:20:43

问题


I want to generate a plot like the following

I am not sure how to generate a shading even though I can get the frame done. I'd like to know the general approach to shade certain areas in a plot in Mathematica. Please help. Thank you.


回答1:


Perhaps you are looking for RegionPlot?

RegionPlot[(-1 + x)^2 + (-1 + y)^2 < 1 && 
 x^2 + (-1 + y)^2 < 1 && (-1 + x)^2 + y^2 < 1 && x^2 + y^2 < 1, 
 {x, 0, 1}, {y, 0, 1}]




回答2:


Note the use of op_ in the following (only one set of equations for the curves and the intersection!):

t[op_] :=Reduce[op[(x - #[[1]])^2 + (y - #[[2]])^2, 1], y] & /@ Tuples[{0, 1}, 2]
tx = Texture[Binarize@RandomImage[NormalDistribution[1, .005], 1000 {1, 1}]];

Show[{

  Plot[y /. ToRules /@ #, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}] &@ t[Equal], 
  RegionPlot[And @@ #, {x, 0, 1}, {y, 0, 1}, PlotStyle -> tx] &@ t[Less]}, 

Frame->True,AspectRatio->1,FrameStyle->Directive[Blue, Thick],FrameTicks->None]




回答3:


If, for any particular reason, you want the dotted effect in your picture, you can achieve this like so:

pts = RandomReal[{0, 1}, {10000, 2}];
pts = Select[pts,
  And @@ Table[Norm[# - p] < 1, {p,
   {{0, 0}, {1, 0}, {1, 1}, {0, 1}}}] &];
Graphics[{Thick,
  Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}],
  Circle[{0, 0}, 1, {0, Pi/2}],
  Circle[{1, 0}, 1, {Pi/2, Pi}],
  Circle[{1, 1}, 1, {Pi, 3 Pi/2}],
  Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}],
  PointSize[Small], Point[pts]
}]



来源:https://stackoverflow.com/questions/8690558/how-to-shade-a-plot-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!