ListContourPlot with hatched regions

KraZug 08/25/2017. 3 answers, 224 views
plotting

I'm using ListContourPlot on a table of data, and I'd like to hash the regions rather than colour them, so the plot works in black and white.

data = Flatten[Table[{x, y, Cos[x] + Cos[y]}, {x, 0, 3, 0.1}, {y, 0, 3, 0.1}], 1]
ListContourPlot[data, Contours -> {-1, 1}]

ContourPlot with 3 coloured regions

I can colour the regions using ContourShading, but I can't figure out how to get it to hash the regions instead of colouring them.

3 Comments
2 Bob Hanlon 08/25/2017
Use option PlotTheme -> "Monochrome". Doesn't use hash but still distinguishes in black and white.
3 Mathe172 08/25/2017
This question might be useful if you insist on hashing the regions, although it might be difficult to achieve artifact free borders

3 Answers


Borrowing from here ( as Mathe172 commented. )

f = Interpolation[data]; Show[
 RegionPlot[f[x, y] < -1, {x, 0, 3}, {y, 0, 3}, Mesh -> 50, 
  MeshFunctions -> {1000 #1 - #2 &}, BoundaryStyle -> None, 
  MeshStyle -> Thickness[.005], PlotStyle -> Transparent],
 RegionPlot[f[x, y] > 1, {x, 0, 3}, {y, 0, 3}, Mesh -> 50, 
  MeshFunctions -> { #2 - #1 &}, BoundaryStyle -> None, 
  MeshStyle -> Thickness[.0005], PlotStyle -> Transparent]]

hashed list contour plot


Update: Towards a more general type of hatched contour-plot type game. Not quite a tool, but maybe someone can bounce off this to make something actually useful.

hatchedContourPlot[data_, regions_, plotOptions___] := 
 Module[{f = Interpolation[data, InterpolationOrder -> All], 
   xRange = Through[{Min, Max}[(First /@ data)]],
   yRange = Through[{Min, Max}[(#[[2]] & /@ data)]], 
   sReg = {-\[Infinity], Sort[regions], \[Infinity]} // Flatten, lSR, 
   x, y, j}, lSR = Length[sReg];
  Show[
   Sequence @@ 
    Table[ RegionPlot[ sReg[[j - 1]] < f[x, y] < sReg[[j]] , 
      Prepend[xRange, x], Prepend[yRange, y], 
      Mesh -> Floor[(70 - (j - 2) (65/(lSR - 3)))], 
      MeshStyle -> Thickness[.005 -  (j - 2) (.0049/(lSR - 1))],
      MeshFunctions -> { 
        Cos[(j - 1) 2 Sqrt[2] \[Pi]/lSR] #1 + 
          Sin[(j - 1) 2 Sqrt[2] \[Pi]/lSR] #2 &}, 
      BoundaryStyle -> {Thick, Gray}, PlotStyle -> Transparent, 
      plotOptions
      ], {j, 2, Floor[Length[sReg]/2] }], 
   RegionPlot[ 
    sReg[[Floor[Length[sReg]/2]]] < f[x, y] < 
     sReg[[Floor[Length[sReg]/2] + 1]], Prepend[xRange, x], 
    Prepend[yRange, y], BoundaryStyle -> {Thick, Gray}, 
    PlotStyle -> Transparent],
   Sequence @@ 
    Table[ RegionPlot[ sReg[[j - 1]] < f[x, y] < sReg[[j]] , 
      Prepend[xRange, x], Prepend[yRange, y], 
      Mesh -> Floor[(70 - (j - 3) (65/(lSR - 3)))], 
      MeshStyle -> Thickness[.005 -  (j - 3) (.0049/(lSR - 1))],
      MeshFunctions -> { 
        Cos[(j - 2) 2 Sqrt[2] \[Pi]/lSR] #1 + 
          Sin[(j - 2) 2 Sqrt[2] \[Pi]/lSR] #2 &}, 
      BoundaryStyle -> {Thick, Gray}, PlotStyle -> Transparent, 
      plotOptions
      ], {j, Floor[Length[sReg]/2] + 2 , Length[sReg]}]]]

Usage:

data2 = Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}], 
    Sin[x y]}, {1000}];
hatchedContourPlot[data2, {-1/2, -1/4, 1/4, 1/2}, PlotPoints -> 100]

results in:

enter image description here


eldo 08/25/2017.

Instead of hatching you could create your own monochrome palettes:

ListContourPlot[data, Contours -> {-1, 1}, 
 ContourShading -> {Black, White, Gray}]

enter image description here

With many contours you could use Blend and add a legend

 ListContourPlot[data,
  Contours -> 12,
  ColorFunction -> (Blend[{Black, White, Black}, #] &),
  PlotLegends -> Automatic]   

enter image description here


Bob Hanlon 08/25/2017.
data = Flatten[Table[{x, y, Cos[x] + Cos[y]}, {x, 0, 3, 0.1}, {y, 0, 3, 0.1}],
    1];

Or eliminate the shading and just use ContourLabels

ListContourPlot[data,
 Contours -> Range[-1, 1, 1/5],
 PlotTheme -> "Monochrome",
 ContourShading -> None,
 ContourLabels -> (Text[Framed[#3, FrameStyle -> Opacity[0]], {#1, #2}, 
     Background -> White] &)]

enter image description here


HighResolutionMusic.com - Download Hi-Res Songs

1 BLACKPINK

Kiss And Make Up flac

BLACKPINK. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
2 Martin Garrix

Waiting For Tomorrow flac

Martin Garrix. 2018. Writer: Pierce Fulton;Mike Shinoda;Martijn Garritsen;Brad Delson.
3 John Legend

Written In The Stars flac

John Legend. 2018. Writer: Kiana Brown;Santoy;Kevin White;Mike Woods;MZMC;The Heavy Group;Rice N' Peas.
4 Martin Garrix

Access flac

Martin Garrix. 2018. Writer: Martin Garrix.
5 Martin Garrix

Yottabyte flac

Martin Garrix. 2018. Writer: Martin Garrix.
6 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
7 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
8 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
9 Post Malone

Sunflower flac

Post Malone. 2018. Writer: Louis Bell;Billy Walsh;Carter Lang;Swae Lee;Post Malone.
10 Dyro

Latency flac

Dyro. 2018. Writer: Martin Garrix;Dyro.
11 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
12 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.
13 Zara Larsson

Ruin My Life flac

Zara Larsson. 2018. Writer: Delacey;Michael Pollack;Stefan Johnson;Jordan Johnson;Sermstyle;Jackson Foote.
14 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
15 ZAYN

Fingers flac

ZAYN. 2018. Writer: Zayn Malik;Alex Oriet;David Phelan.
16 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
17 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
18 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
19 Blinders

Breach (Walk Alone) flac

Blinders. 2018. Writer: Dewain Whitmore;Ilsey Juber;Blinders;Martin Garrix.
20 Julia Michaels

There's No Way flac

Julia Michaels. 2018. Writer: Ian Kirkpatrick;Justin Tranter;Julia Michaels;Lauv.

Related questions

Hot questions

Language

Popular Tags