Message Boards Message Boards

0
|
1714 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

In ListDensityPlot[ ], how can I get a consistent coloring scheme?

Posted 2 years ago

I have a problem with density plots. I have 4 classes, 0 to 3, that I want to assign fixed colours. My problem is, that if one of the classes, eg class 0, is missing in the data, this messes up the colouring scheme, as data belonging to class 1 will take the colour of class 0, etc..

Here's code to reproduce this problem:

data1 = Table[{RandomReal[{0, 10}], RandomReal[{0, 5}],
  RandomChoice[{0, 1, 2, 3}]}, 100];
data2 = Table[{RandomReal[{0, 10}], RandomReal[{0, 5}],
  RandomChoice[{1, 2, 3}]}, 100];

mylegend = 
  PointLegend[{
   RGBColor[0.237736, 0.340215, 0.575113],
   RGBColor[0.277947,0.45009699999999997`,0.32815550000000004`],
   RGBColor[0.72987, 0.239399, 0.230961],
   RGBColor[0.8562609999999999, 0.742794, 0.31908333333333333`]},
  {"Class 0", "Class 1", "Class 2", "Class 3"}, LegendMarkerSize -> 20]; 

ListDensityPlot[data1, InterpolationOrder -> 0, PlotLegends -> mylegend,
  ColorFunction -> "DarkRainbow", FrameLabel -> {x, y},
  LabelStyle -> Large, RotateLabel -> False]
ListDensityPlot[data2, InterpolationOrder -> 0, PlotLegends -> mylegend,
  ColorFunction -> "DarkRainbow", FrameLabel -> {x, y},
  LabelStyle -> Large, RotateLabel -> False]

Here are results that this code may produce: enter image description here

Attachments:
POSTED BY: Takashi Imanaka

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. Posting code Images doesn't help other members to copy your code. Please EDIT your post and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

You can also embed notebook or attach notebook.

enter image description here

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract