# Avoid the following density plot artifacts?

**URL:** <https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559>\
**Category:** Questions\
**Tags:** wolfram-u, equation-solving, graphics-and-visualization, modeling\
**Created:** [June 5, 2018, 5:50am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559 "2018-06-05T05:50:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 5, 2018, 5:50am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/1 "2018-06-05T05:50:17Z")

</div>

Please run the attached code. The density plot has some artifacts on it (The light blue parts around the circle) Is there a way to resolve this issue. The density plot is showing velocity of a liquid passing through the channel. Regards.

[CapitalOmega] =  
ImplicitRegion[  
0 \<= x \<= 2.0 &&  
0 \<= y \<=  
0.48208 && ! (x \>= 1.0 && y \<= 0.19) && ! (x \>= 1.0 &&  
y \>= 0.31) && ! ((x - 0.76)^2 + (y - 0.24104)^2 \<=  
0.238125^2), {x, y}];  
RegionPlot[[CapitalOmega], AspectRatio → Automatic, ImageSize → 300]  
stokesFlowOperator = {Div[({{-1, 0}, {0, -1}}.Grad[  
u[x, y], {x, y}]), {x, y}] +  
!\*SuperscriptBox[\(w,  
TagBox[  
RowBox[{“(”,  
RowBox[{“1”, “,”, “0”}], “)”}],  
Derivative],  
MultilineFunction-\>None])[x, y],  
Div[({{-1, 0}, {0, -1}}.Grad[v[x, y], {x, y}]), {x, y}] +  
!\*SuperscriptBox[\(w,  
TagBox[  
RowBox[{“(”,  
RowBox[{“0”, “,”, “1”}], “)”}],  
Derivative],  
MultilineFunction-\>None])[x, y],

!\*SuperscriptBox[\(v,  
TagBox[  
RowBox[{“(”,  
RowBox[{“0”, “,”, “1”}], “)”}],  
Derivative],  
MultilineFunction-\>None])[x, y] +  
!\*SuperscriptBox[\(u,  
TagBox[  
RowBox[{“(”,  
RowBox[{“1”, “,”, “0”}], “)”}],  
Derivative],  
MultilineFunction-\>None])[x, y]};  
Subscript[[CapitalGamma],  
D] = {DirichletCondition[{u[x, y] == -1, v[x, y] == 0}, x == 0.],  
DirichletCondition[{u[x, y] == 1., v[x, y] == 0}, 0 \< x \< 2.0],  
DirichletCondition[w[x, y] == 0.1, x == 2.0]};  
{xVel, yVel, pressure} =  
NDSolveValue[{stokesFlowOperator == {0, 0, 0},  
Subscript[[CapitalGamma], D]}, {u, v,  
w}, {x, y} [Element] [CapitalOmega],  
Method → {“FiniteElement”,  
“InterpolationOrder” → {u → 2, v → 2, w → 1}}];  
rmf = RegionMember[[CapitalOmega]];  
Show[BoundaryDiscretizeRegion[[CapitalOmega]],  
DensityPlot[{xVel[x, y], yVel[x, y]}, {x, 0, 2.0}, {y, 0, 0.48208},  
RegionFunction → Function[{x, y}, rmf[{x, y}]],  
AspectRatio → Automatic, PlotLegends → Automatic,  
ColorFunction → ColorData[“BlueGreenYellow”], PlotPoints → 20],  
ImageSize → 1000]

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 5, 2018, 6:35am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/2 "2018-06-05T06:35:28Z")

</div>

The artifacts are probably due to clipping. Compare:

```
Plot3D[{xVel[x, y], yVel[x, y]}, {x, 0, 2.0}, {y, 0, 0.48208}, 
 RegionFunction -> Function[{x, y}, rmf[{x, y}]], 
 AspectRatio -> Automatic, PlotLegends -> Automatic, 
 ColorFunction -> ColorData["BlueGreenYellow"], PlotPoints -> 40, 
 PlotRange -> All]
Plot3D[{xVel[x, y], yVel[x, y]}, {x, 0, 2.0}, {y, 0, 0.48208}, 
 RegionFunction -> Function[{x, y}, rmf[{x, y}]], 
 AspectRatio -> Automatic, PlotLegends -> Automatic, 
 ColorFunction -> ColorData["BlueGreenYellow"], PlotPoints -> 40]

```

You may try a rescaling of your velocity field to help visualization.

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 5, 2018, 6:56am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/3 "2018-06-05T06:56:59Z")

</div>

Thanks for helping. What is the first thing to carry out which will be a remedy for this. So does the 3D plots show the function is actually calculated at the points where artifacts appear so should I infer that those regions are not properly displayed by the density plot?

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 5, 2018, 7:32am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/4 "2018-06-05T07:32:20Z")

</div>

You can set `PlotRange -> All` in the density plot, but that will flatten most of the picture. It is like taking a photograph of a scene which is low-lit except for a very bright detail. You may try rescaling the `ColorFunction`, like this:

```
DensityPlot[{xVel[x, y], yVel[x, y]}, {x, 0, 2.0}, {y, 0, 0.48208}, 
 RegionFunction -> Function[{x, y}, rmf[{x, y}]], 
 AspectRatio -> Automatic, PlotLegends -> Automatic, 
 ColorFunction -> 
  Function[z, 
   ColorData["BlueGreenYellow"][Rescale[ArcTan[z/5], Pi/2 {-1, 1}]]], 
 PlotPoints -> 40, PlotRange -> All, ColorFunctionScaling -> False]

```

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 6, 2018, 6:46am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/5 "2018-06-06T06:46:05Z")

</div>

Your code works. Thanks!

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 8, 2018, 4:30am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/6 "2018-06-08T04:30:37Z")

</div>

May you please check the following word file? I marked 3 different regions on the graph. The density plot shows the velocity of the liquid Passing through the region. Region 1 shows high velocity values. Region 2 shows almost 0 velocity value within a relatively similar channel width of region 1 and then Region 3 shows moderate velocity values due to channel width becoming wider. While regions 1 and 3 are consistent. Region 2 seems to display an irrelevant velocity which is not in agreement with the Regions 1 and 3. Do you have an explanation for this? I have also attached the Mathematica Code.  
Regards.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 8, 2018, 6:09am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/7 "2018-06-08T06:09:04Z")

</div>

You are using `DensityPlot` with two functions. This is not documented, and I don’t know what gets plotted this way. If what you are trying to plot is the scalar velocity field, you may try this:

```
DensityPlot[
 Norm@{xVel[x, y], yVel[x, y]}, {x, 0, 2.0}, {y, 0, 0.48208}, 
 RegionFunction -> Function[{x, y}, rmf[{x, y}]], 
 AspectRatio -> Automatic, PlotLegends -> Automatic, 
 ColorFunction -> 
  Function[z, 
   ColorData["BlueGreenYellow"][Rescale[ArcTan[z/2], Pi/2 {-1, 1}]]], 
 PlotPoints -> 80, PlotRange -> All, ColorFunctionScaling -> False]

```

The `ArcTan[z/2]` part is meant to somehow equalize the wild variations in the velocity field. Changing the parameters, for example with `ArcTan[z/5]` will move the focus to slightly higher velocity ranges. You may want to experiment with that. A `Plot3D` may help visualization too.

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 8, 2018, 8:15pm UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/8 "2018-06-08T20:15:21Z")

</div>

Thanks and Best regards

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 13, 2018, 5:39am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/9 "2018-06-13T05:39:31Z")

</div>

Hi Gianluca, May you please check the following file, inquiry 2 and let me know. I calculated magnitude of velocity at different points within the channel at the right side and found that the velocities at the boundary of the channel (Region 2) is greater than in the middle (Region 1). However it is expected to have a lower velocity at the boundary (Region 2) than at the middle (Region 1). Do you have an explanation for this? Also the channel on the left side (Region 3) displays the right velocities. Lower at the boundary and higher in the middle. Furthermore Region 4, 5 and 6 is unexpectedly displaying almost 0 velocity after a relatively large flow velocities. Please send help regarding this issue. Regards.

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 13, 2018, 5:39am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/10 "2018-06-13T05:39:46Z")

</div>

Hi Gianluca, May you please check the following file, inquiry 2 and let me know. I calculated magnitude of velocity at different points within the channel at the right side and found that the velocities at the boundary of the channel (Region 2) is greater than in the middle (Region 1). However it is expected to have a lower velocity at the boundary (Region 2) than at the middle (Region 1). Do you have an explanation for this? Also the channel on the left side (Region 3) displays the right velocities. Lower at the boundary and higher in the middle. Furthermore Region 4, 5 and 6 is unexpectedly displaying almost 0 velocity after a relatively large flow velocities. Please send help regarding this issue. Regards.

---

<div class="post-metadata">

**Author:** ![cmutlu](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@cmutlu](https://community.wolfram.com/u/cmutlu)\
**Post date:** [June 13, 2018, 5:41am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/11 "2018-06-13T05:41:30Z")

</div>

Hi Gianluca, May you please check the following file, inquiry 2 and let me know. I calculated magnitude of velocity at different points within the channel at the right side and found that the velocities at the boundary of the channel (Region 2) is greater than in the middle (Region 1). However it is expected to have a lower velocity at the boundary (Region 2) than at the middle (Region 1). Do you have an explanation for this? Also the channel on the left side (Region 3) displays the right velocities. Lower at the boundary and higher in the middle. Furthermore Region 4, 5 and 6 is unexpectedly displaying almost 0 velocity after a relatively large flow velocities. Please send help regarding this issue. Regards.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 13, 2018, 6:08am UTC](https://community.wolfram.com/t/avoid-the-following-density-plot-artifacts/12559/12 "2018-06-13T06:08:04Z")

</div>

The result seems a bit unintuitive to me too, but I have no expertise in fluid mechanics, where intuition fails a lot.
