Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to fill a region with lines:

Plot[{t + 1, t}, {t, 0, 4}, PlotRange -> {0, 4},Filling -> {1 -> {2}}]

I want to change the filling style to vertical lines, as shown in the right figure below. How should I change the code? enter image description here

share|improve this question
3  
In addition to the answe below, you may want to search this site for "hatched" or "hashed" filling. There have been a few examples, the best of which seem to rely on using a RegionPlot of the region and mesh lines. – MarcoB Mar 21 at 4:11
    
Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Mar 21 at 8:48
2  
Strongly related: "Generating hatched filling using Region functionality." – Alexey Popkov Mar 21 at 8:57
funs = {t + 1, t};

Show[{Plot[funs, {t, 0, 4}, PlotRange -> {0, 4}], 
      RegionPlot[funs[[2]] < y < funs[[1]], {t, 0, 10}, {y, 0, 6}, 
                 Mesh -> 60, MeshFunctions -> {#1 &}, BoundaryStyle -> None, 
                 MeshStyle -> {Gray, Thickness[.001]}, PlotStyle -> Transparent]}]

Mathematica graphics

Just for fun,to show the flexibility of this method:

Show[{Plot[funs, {t, 0, 4}, PlotRange -> {0, 4}], 
  RegionPlot[funs[[2]] < y < funs[[1]], {t, 0, 10}, {y, 0, 6}, 
   Mesh -> 60, MeshFunctions -> {Sin[#1] Sin[#2] &}, 
   BoundaryStyle -> None, MeshStyle -> {Gray, Thickness[.001]}, 
   MeshShading -> {Red, Green, None, Yellow}, 
   PlotStyle -> Transparent]}]

Mathematica graphics

share|improve this answer

you could use GridLines also

Plot[{t + 1, t}, {t, 0, 4}, PlotRange -> {0, 4}, 
 GridLines -> {Range[0, 4, .2], None}, 
 Filling -> {1 -> {Top, White}, 2 -> {Bottom, White}}]

enter image description here

share|improve this answer

I guess the simplest way is:

Show[
 ListPlot[{
   Table[i*2 + 1, {i, -1, 3, 0.1}],
   Table[i*2 + 3, {i, -1, 3, 0.1}]}, Joined -> True],
 ListPlot[{
   Table[i*2 + 1, {i, -1, 3, 0.1}],
   Table[i*2 + 3, {i, -1, 3, 0.1}]
   }, Joined -> False, Filling -> {1 -> {2}}, 
  PlotStyle -> PointSize[0.001]]
 ]

The point-based representation allows to have a discrete line-based filling.

enter image description here

share|improve this answer

Using Epilog

Plot[{t + 1, t}, {t, 0, 4}, 
 PlotRange -> {0, 4}, 
 Epilog -> Line /@ (Thread@{#, {# + 1, #}} & /@ Range[0, 4, 0.2])]

enter image description here

share|improve this answer

A modification of Rom38's.

Show[
 Plot[{t + 1, t}, {t, 0, 4}, PlotRange -> {0, 4}],
 ListLinePlot[Table[{{i, i + 1}, {i, i}}, {i, 0, 4, 0.2}], PlotStyle -> {{Gray, Thin}}]
 ]

enter image description here

Another option with Epilog:

Plot[{t + 1, t}, {t, 0, 4}, PlotRange -> {0, 4}, 
 Epilog -> Table[Line @ {{i, i}, {i, i + 1}}, {i, 0, 4, 0.2}]]

enter image description here

share|improve this answer

Here's yet another way to get what you are going for, by using ContourPlot

ContourPlot[#, {x, 0, 4}, {y, 0, 4}, ContourShading -> False, 
    Contours -> 20] & /@ {{x == y,
    x + 1 == y},
   Piecewise[{{x, x < y < x + 1}}, Indeterminate]} // Show

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.