Mathematica - Specific shading vs global - Mesh or ListPlot?

In summary, the code is trying to shade two portions of a polygon defined by a dotted line. The Mesh and MeshFunction commands only allow for global shading, so the best tool is to use another polygon with some transparency over the desired portion. This can be achieved by using the Opacity command and making the edges transparent.
  • #1
sirole
3
0
Hi, I am trying to shade two portions of the polygon defined by the dotted line in this code. The Mesh and MeshFunction cmds seem to allot global shading only. What is the best tool to shade, say half of the aforementioned polygon?

Function[{LtMarg, BotMarg, RtMarg, HVal, DVal, rVal},
Graphics[{Mesh -> True, EdgeForm[{Thick, Blue}], FaceForm[Pink],
Polygon[{{0.5, 0}, {1/2,
HVal - 1/2}, {(HVal - DVal + 1)/2, (DVal + HVal - 1)/
2}, {(HVal - DVal + 1)/2, 0}}], EdgeForm[{Thick, Green}],
White, Rectangle[], Blue, Text[0, {0.01, BotMarg}],
Text[0, {LtMarg, 0}], Text[l, {LtMarg, 1}], Text[t, {1, BotMarg}],
Line[{{0, HVal}, {0.5, HVal - 0.5}, {1, HVal}}],
Line[{{0.5, HVal - 0.5}, {0.5, 0}}],
Line[{{0, DVal}, {0.5, DVal - 0.5}, {1, DVal}}],
Text[Vh, {LtMarg, HVal}], Text[Vd, {LtMarg, DVal}],
Text[Vh, {RtMarg, HVal}], Text[Vd, {RtMarg, DVal}], Dotted,
Line[{{(DVal - HVal + 1)/2,
0}, {(DVal - HVal + 1)/2, (DVal + HVal - 1)/2}, {1/2,
HVal - 1/2}, {(HVal - DVal + 1)/2, (DVal + HVal - 1)/
2}, {(HVal - DVal + 1)/2,
0}}]}]][-0.03, -0.03, 1.035, 0.8, 0.65, 0.1]
 
Physics news on Phys.org
  • #2
I would just put another polygon over it, with some transparency in both the poly and its edges.

Code:
Function[{LtMarg, BotMarg, RtMarg, HVal, DVal, rVal}, 
  Graphics[{Mesh -> True, EdgeForm[{Thick, Blue}], FaceForm[Pink], 
    Polygon[{{0.5, 0}, {1/2, 
       HVal - 1/2}, {(HVal - DVal + 1)/2, (DVal + HVal - 1)/
        2}, {(HVal - DVal + 1)/2, 0}}], EdgeForm[{Thick, Green}], 
    White, Rectangle[], Blue, Text[0, {0.01, BotMarg}], 
    Text[0, {LtMarg, 0}], Text[l, {LtMarg, 1}], Text[t, {1, BotMarg}],
     Line[{{0, HVal}, {0.5, HVal - 0.5}, {1, HVal}}], 
    Line[{{0.5, HVal - 0.5}, {0.5, 0}}], 
    Line[{{0, DVal}, {0.5, DVal - 0.5}, {1, DVal}}], 
    Text[Vh, {LtMarg, HVal}], Text[Vd, {LtMarg, DVal}], 
    Text[Vh, {RtMarg, HVal}], Text[Vd, {RtMarg, DVal}], Dotted, 
    Line[{{(DVal - HVal + 1)/2, 
       0}, {(DVal - HVal + 1)/2, (DVal + HVal - 1)/2}, {1/2, 
       HVal - 1/2}, {(HVal - DVal + 1)/2, (DVal + HVal - 1)/
        2}, {(HVal - DVal + 1)/2, 0}}], Opacity[0.2], 
    EdgeForm[{Transparent}], 
    Polygon[{{(DVal - HVal + 1)/2, 
       0}, {(DVal - HVal + 1)/2, (DVal + HVal - 1)/2}, {1/2, 
       HVal - 1/2}, {1/2, 0}}]}]][-0.03, -0.03, 1.035, 0.8, 0.65, 0.1]
 
  • #3
Ah! Thank you! That is what I ultimately needed to do, and was trying to make into a more difficult task!
 

1. What is the difference between specific shading and global shading in Mathematica?

Specific shading in Mathematica refers to the ability to apply a specific color or shading scheme to individual data points or regions in a plot, while global shading applies the same color or shading to the entire plot. This allows for more customization and control over the appearance of a plot.

2. How do I apply specific shading to a plot in Mathematica?

To apply specific shading in Mathematica, you can use the PlotStyle option within the Plot function. This allows you to specify the color or shading scheme for each data point or region in the plot.

3. What is the purpose of using mesh in a Mathematica plot?

The Mesh option in Mathematica allows you to add gridlines or data points to a plot, making it easier to visualize and analyze the data. It can also be used to highlight specific data points or regions in the plot.

4. Can I use both mesh and specific shading in a Mathematica plot?

Yes, you can use both mesh and specific shading in a Mathematica plot. You can specify the mesh using the Mesh option and then use the PlotStyle option to apply specific shading to the plot.

5. Is it better to use ListPlot or Plot with mesh and specific shading in Mathematica?

This ultimately depends on the type of data and the desired visualization. ListPlot is better suited for discrete data points, while Plot is better for continuous data. However, both can be used with mesh and specific shading to achieve different visual effects.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top