Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • New papers on colorpalette and ColrSpace

    Two new papers providing extensive documentation of Stata command colorpalette and Mata class ColrSpace are now available: The first paper contains an appendix illustrating all named colors and predefined palettes provided by colorpalette and ColrSpace.
    ben

  • #2
    Ben Jann , I have a question which I hope you can answer: how can I define my own colors with an associated name, such that I can then use them like any other saved color name in Stata?


    I have corporate design colors which I want to use and for which I have the RGB (and CMYK and HEX) codes. I would like to name them, doing something like this:

    Code:
    "0 122  150"  name(company_blue)
    "145 5  106"  name(company_purple)
    "114 121 28"  name(company_green)
    -company_blue- would then be a color like any other and could be used ad-hoc for figures, and also commands for intensity could then be used, e.g. -lcolor(company_blue*0.3)- (this is something that does not work with RGB codes: in ,-lcolor("0 122 150" *0.3)- the change in color intensity is simply ignored).

    Comment


    • #3
      A trick i learned in that regard
      you can create files as follows

      filename: color-company_blue.style

      contents
      sequence 7
      label resource "Company blue"
      set rgb "0 122 150"

      Save file in "ado/plus/style"
      after you restart stata, the color name will be available in the system

      Fernando

      Comment


      • #4
        Thank you FernandoRios !

        And here it is how you can write your solution from within a do-file (so that it can be shared easily with others):

        Code:
        cd  "~/ado/plus/style"
        
        file open myfile using "color-company_blue.style", write replace
        
        file write myfile "sequence 7" _newline "label resource " _char(34) "Company blue" _char(34) _newline "set rgb " _char(34) "0 122 150" _char(34)
        
        file close myfile

        Comment


        • #5
          Nice! thank you. Another trick to the pocket

          Comment


          • #6
            Originally posted by FernandoRios View Post
            A trick i learned in that regard
            you can create files as follows

            filename: color-company_blue.style

            contents
            sequence 7
            label resource "Company blue"
            set rgb "0 122 150"

            Save file in "ado/plus/style"
            after you restart stata, the color name will be available in the system

            Fernando
            Has someone an idea what "sequence 7" is doing?
            I have a simple file that only contains set rgb "181 203 214" and the color name is recognised by the filename...

            PS: And I have mine in ado/personal/style - path...

            Comment


            • #7
              To make the colors available you can type:

              Code:
              colorpalette "0 122 150" "145 5 106" "114 121 28", stylefiles(company_blue company_purple company_green)
              This will create appropriate style files and store them in folder "style" in the current working directory. The colors will be available as long as you do not change the working directory. Alternatively, type:

              Code:
              colorpalette "0 122  150" "145 5  106" "114 121 28", stylefiles(company_blue company_purple company_green, personal)
              In this case the style files will be stored in folder "style" in the personal ado folder (see -help sysdir-) and the colors will be permanently available.

              Either way, you can then use the colors e.g. as follows:

              Code:
              sysuse auto
              scatter trunk turn mpg weight, mc(company_blue company_purple company_green)
              (Be aware that the index of available colors will be built when the graph system is loaded, i.e. when the first graph is created. So you may need to flush the graph memory to make the added colors available. To flush graph memory, you can type -disrcard- or -clear all- or restart Stata.)

              Also see section 4.8 in https://ideas.repec.org/p/bss/wpaper/43.html

              ben

              Comment

              Working...
              X