2
$\begingroup$

When plotting the data using SMTShowMesh in AceFEM package I would like to use my own color function not the one that SMTShowMesh uses by default. For this to be achieved, I created my own color function using the following command,

mycolorTemp =  
 Blend[{{-7 + colorstep*0 , color1} , {-7 + colorstep*1 , 
     color2} , {-7 + colorstep*2, color3} , {-7 + colorstep*3 , 
     color4} , {-7 + colorstep*4, color5} , {-7 + colorstep*5 , 
     color6} , {-7 + colorstep*6 , color7} , {-7 + colorstep*7, 
     color8} , {-7 + colorstep*8, color9} , {-7 + colorstep*9, 
     color10} , {-7 + colorstep*10 , color11} , {-7 + colorstep*11, 
     color12} , {-7 + colorstep*12 , color13} , {-7 + colorstep*13, 
     color14} , {-7 + colorstep*14 , color15} , {-7 + colorstep*15 , 
     color16} , {-7 + colorstep*16 , color17} , {-7 + colorstep*17, 
     color18} , {-7 + colorstep*18, color19} , {-7 + colorstep*19 , 
     color20} , {-7 + colorstep*20, color21} , {-7 + colorstep*21, 
     color22} , {-7 + colorstep*22 , color23} , {-7 + colorstep*23, 
     color24} , {-7 + colorstep*24, color25} , {-7 + colorstep*25 , 
     color26} , {-7 + colorstep*26, color27} , {-7 + colorstep*27 , 
     color28} , {-7 + colorstep*28, color29} , {-7 + colorstep*29, 
     color30} , {-7 + colorstep*30, color31} , {-7 + colorstep*31, 
     color32} , {-7 + colorstep*32, color33} , {-7 + colorstep*33, 
     color34} , {-7 + colorstep*34, color35} , {-7 + colorstep*35, 
     color36} , {-7 + colorstep*36, color37} , {-7 + colorstep*37, 
     color38} , {-7 + colorstep*38, color39} , {-7 + colorstep*39, 
     color40} , {-7 + colorstep*40, color41} , {-7 + colorstep*41, 
     color42} , {-7 + colorstep*42, color43} , {-7 + colorstep*43, 
     color44} , {-7 + colorstep*44, color45} , {-7 + colorstep*45 , 
     color46} , {-7 + colorstep*46, color47}} , #1] &

where color1 to color 47 is defined as,

color1 = RGBColor[0/255 , 0/255 , 0/255];
color2 = RGBColor[31.875/255 , 0/255 , 31.875/255];
color3 = RGBColor[63.75/255 , 0/255 , 63.75/255];
color4 = RGBColor[95.625/255 , 0/255 , 95.625/255];
color5 = RGBColor[127.50/255 , 0/255 , 127.50/255];
color6 = RGBColor[159.375/255 , 0/255 , 159.375/255];
color7 = RGBColor[191.25/255 , 0/255 , 191.25/255];
color8 = RGBColor[223.125/255 , 0/255 , 223.125/255];
color9 = RGBColor[255/255 , 0/255 , 255/255];
color10 = RGBColor[204/255 , 0/255 , 255/255];
color11 = RGBColor[153/255 , 0/255 , 255/255];
color12 = RGBColor[102/255 , 0/255 , 255/255];
color13 = RGBColor[51/255 , 0/255 , 255/255];
color14 = RGBColor[0/255 , 0/255 , 255/255];
color15 = RGBColor[0/255 , 31.875/255 , 255/255];
color16 = RGBColor[0/255 , 63.75/255 , 255/255];
color17 = RGBColor[0/255 , 95.625/255 , 255/255];
color18 = RGBColor[0/255 , 127.50/255 , 255/255];
color19 = RGBColor[0/255 , 159.375/255 , 255/255];
color20 = RGBColor[0/255 , 191.25/255 , 255/255];
color21 = RGBColor[0/255 , 223.125/255 , 255/255];
color22 = RGBColor[0/255 , 255/255 , 255/255];
color23 = RGBColor[0/255 , 255/255 , 204/255];
color24 = RGBColor[0/255 , 255/255 , 153/255];
color25 = RGBColor[0/255 , 255/255 , 102/255];
color26 = RGBColor[0/255 , 255/255 , 51/255];
color27 = RGBColor[0/255 , 255/255 , 0/255];
color28 = RGBColor[51/255 , 255/255 , 0/255];
color29 = RGBColor[102/255 , 255/255 , 0/255];
color30 = RGBColor[153/255 , 255/255 , 0/255];
color31 = RGBColor[204/255 , 255/255 , 0/255];
color32 = RGBColor[255/255 , 255/255 , 0/255];
color33 = RGBColor[255/255 , 229.50/255 , 0/255];
color34 = RGBColor[255/255 , 204/255 , 0/255];
color35 = RGBColor[255/255 , 178.50/255 , 0/255];
color36 = RGBColor[255/255 , 153/255 , 0/255];
color37 = RGBColor[255/255 , 127.50/255 , 0/255];
color38 = RGBColor[255/255 , 102/255 , 0/255];
color39 = RGBColor[255/255 , 76.50/255 , 0/255];
color40 = RGBColor[255/255 , 51/255 , 0/255];
color41 = RGBColor[255/255 , 25.50/255 , 0/255];
color42 = RGBColor[255/255 , 0/255 , 0/255];
color43 = RGBColor[255/255 , 51/255 , 51/255];
color44 = RGBColor[255/255 , 102/255 , 102/255];
color45 = RGBColor[255/255 , 153/255 , 153/255];
color46 = RGBColor[255/255 , 204/255 , 204/255];
color47 = RGBColor[255/255 , 255/255 , 255/255];

However using this color function and putting it in the following SMTshowMesh command,

SMTShowMesh["ColorFunction" -> (mycolorTemp) , "Contour" -> True, 
 "Field" -> "Theta", "Legend" -> True, "Mesh" -> False, 
 ImageSize -> 250, ViewPoint -> Front, 
 Lighting -> {{"Ambient", White}}]

gives the following figure

enter image description here

which is not correct because the values that are displayed on the barlegend possess different colors according to my colorfunction, not the ones being displayed. What is my mistake here?

$\endgroup$
5
$\begingroup$

Domain of color function f used in SMTShowMesh["ColorFunction"->f, ...] should go from 0 to 1 and then contours and legend are adjusted automatically for the values of chosen "Field".

An example using OP's color list and the first large example from AceFEM documentation ("Simple bending of the column"). First we collect all colors defined in OP in a list.

colorList = ToExpression@Table["color" <> ToString[i], {i, 1, 47}]

colorList

Colors are evenly spaced over the domain interval so we can use the simpler syntax of Blend, which assumes linear interpolation between 0 and 1.

SMTShowMesh[
 "ColorFunction" -> (Blend[colorList, #] &),
 "DeformedMesh" -> True,
 "Contour" -> True,
 "Field" -> "Mises*",
 "Mesh" -> False
 ]

contourPlot

Also, instead of fiddling with RGBColors a similar color function can be defined with named colors.

colorList={Black, Magenta, Blue, Cyan, Green, Yellow, Red, White};

Graphics[
 Raster[{Range[100]/100}, ColorFunction -> (Blend[colorList, #] &)], 
 AspectRatio -> 0.1
]

raster

| improve this answer | |
$\endgroup$
  • $\begingroup$ nice and complete as always. Thanks $\endgroup$ – KratosMath Jul 11 '18 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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