4
$\begingroup$

I have a package that is destined to plot stuff. The plots can have as many functions as the user wants so the variety of the color in the plots has to be enough. Which is why I created a new color gradient as it was explained in this question.

The code itself that adds the color gradient is

Unprotect[ColorData];
Clear[new2];
new2 = {{"Hueeee", "", {}}, {"Gradients"}, 
  1, {0, 1}, {Hue[0.33, 1, 0.58], Hue[0.6, 1, 0.9], 
   RGBColor[0.471412, 0.108766, 0.527016], Hue[0.9, 1, 0.9], 
   Hue[1, 1, 0.9], Hue[0.1, 1, 0.9]}, ""};
AppendTo[DataPaclets`ColorDataDump`colorSchemes, new2];
AppendTo[DataPaclets`ColorDataDump`colorSchemeNames, new2[[1, 1]]];

Its first output is

AppendTo::rvalue: DataPaclets`ColorDataDump`colorSchemes is not a variable with a value, so its value cannot be changed.
AppendTo::rvalue: DataPaclets`ColorDataDump`colorSchemeNames is not a variable with a value, so its value cannot be changed.

And the user-defined color data doesn't exist. If I run that code again it creates the color data as intended.

My question is, first, how can I make it so that running that code only once will create my color scheme? And second, how can I make it so the color scheme is added as soon as the package is imported? My understanding is that you put definition of functions inside Private, but I don't know if you actually write commands so that they are run and imported back to the notebook.

Thanks!

$\endgroup$
  • $\begingroup$ It's probably because something is only loaded on-demand. To force loading, add e.g. ColorData; somewhere in your code before you call AppendTo. This should force loading of the data structures necessary. $\endgroup$ – MarcoB Jun 13 '18 at 18:34
  • $\begingroup$ That doesnt seem to do anything. I cant get the new gradient to be added, instead this message appears Pick::incomp: Expressions {<<1>>} and {Atoms,Crayola,GeologicAges,HTML,Legacy,WebSafe,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,<<198>>} have incompatible shapes.. $\endgroup$ – M.O. Jun 13 '18 at 19:10
6
$\begingroup$

Your initial problem was due to the autoloading done by ColorData, as suggested by @MarcoB. The subsequent issue, which you only mention in the comments, is that both:

DataPaclets`ColorDataDump`colorSchemes
DataPaclets`ColorDataDump`colorSchemeNames

are also auto-loaded, and you need to finish the auto-loading before you try to append to the symbols. So, the following should do what you want:

(* force autoloading *)
ColorData[];
DataPaclets`ColorDataDump`colorSchemes;
DataPaclets`ColorDataDump`colorSchemeNames;

(* your code *)
Unprotect[ColorData];
Clear[new2];
new2 = {
    {"Hueeee", "", {}},
    {"Gradients"},
    1,
    {0,1},
    {
        Hue[0.33,1,0.58], Hue[0.6,1,0.9], RGBColor[0.471412,0.108766,0.527016],
        Hue[0.9,1,0.9], Hue[1,1,0.9], Hue[0.1,1,0.9]
    },
    ""
};
AppendTo[DataPaclets`ColorDataDump`colorSchemes,new2];
AppendTo[DataPaclets`ColorDataDump`colorSchemeNames,new2[[1,1]]];

I didn't get any errors, and:

ColorData["Gradients"]

{"AlpineColors", "Aquamarine", "ArmyColors", "AtlanticColors", "AuroraColors", "AvocadoColors", "BeachColors", "BlueGreenYellow", "BrassTones", "BrightBands", "BrownCyanTones", "CandyColors", "CherryTones", "CMYKColors", "CoffeeTones", "DarkBands", "DarkRainbow", "DarkTerrain", "DeepSeaColors", "FallColors", "FruitPunchColors", "FuchsiaTones", "GrayTones", "GrayYellowTones", "GreenBrownTerrain", "GreenPinkTones", "Hueeee", "IslandColors", "LakeColors", "LightTemperatureMap", "LightTerrain", "MintColors", "NeonColors", "Pastel", "PearlColors", "PigeonTones", "PlumColors", "Rainbow", "RedBlueTones", "RedGreenSplit", "RoseColors", "RustTones", "SandyTerrain", "SiennaTones", "SolarColors", "SouthwestColors", "StarryNightColors", "SunsetColors", "TemperatureMap", "ThermometerColors", "ValentineTones", "WatermelonColors"}

included your new gradient.

$\endgroup$
  • $\begingroup$ Thanks, that did it! If someone is interested on the other question, I created a function inside the package called addGradient[] that has those commands in it, and run it inside the plot functions that need it... not the ideal but it works. Thanks! $\endgroup$ – M.O. Jun 13 '18 at 20:50

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.