Announcement

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

  • Match text color to line color

    In a Stata graph, I sometimes use colored text to label colored lines, but it's sometimes hard to match the shades. The code below is an example. I've made the upper text orange and the lower text blue, but the orange and blue of the text don't quite match the orange and blue of the lines. How can I better match the text color to the line color? When I inspect the line colors in the Graph Editor, they show as "Custom."

    Code:
    set scheme white_tableau
    
    twoway function y=1-(1-.05)^x, range(1 20) || function y=1-(1-.10)^x, range(1 20) lpattern(dash) ///
     text(.29 10 "Blue", color(blue)) text(.77 10 "Orange", color(orange))

  • #2
    Just a quick note, white_tableau is part of a user contributed package called "schemepack".

    In the graph editor, first click on the line, then right click and select "line properties." Directly to the right of "Color: Custom" you should see a box showing the custom color. Click the colored box. Now select "Define Custom Colors >>". The color attributes should appear to the right. Click add to custom colors. That should add the color to the custom color palate. Close both dialogue boxes.

    Next, right click and select "text box properties" on the text box. On the color drop down, select custom, then select the custom color from the pallet.

    I think you are going to have to fully specify the color you want to match if you want to do this programmatically. You can get the custom color RBG or HSV values from the custom color menu. Then you can specify the color you want to match like so:

    Code:
    set scheme white_tableau
    
    twoway function y=1-(1-.05)^x, range(1 20) || function y=1-(1-.10)^x, range(1 20) lpattern(dash) ///
     text(.29 10 "Blue", color("31 119 180")) text(.77 10 "Orange", color("255 127 14"))
    Edit: You might also want to look through -help colorstyle-.
    Last edited by Daniel Schaefer; 23 Jan 2024, 22:40.

    Comment

    Working...
    X