2
$\begingroup$

I am using Show to display a set of lines. Now I am trying to label them inside the plot with P=0/0.25/0.5/0.75/0.9. However, as you can see from the attached plot, the text seems to center around 0.2, instead of being left aligned at 0.2. How can I get the 5 lines to be left aligned, and all starting at 0.2?

Show[plot, Graphics[{Text["--P=0", {0.2, 5.5}, 
TextStyle -> Directive[Bold, RGBColor["#123c69"], Medium]]}], 
Graphics[{Text["--P=0.25", {0.2, 5}, TextStyle -> Directive[Bold, 
RGBColor["#bab2b5"], Dashed, Medium]]}], Graphics[{Text["--P=0.5", {0.2, 4.5}, 
TextStyle -> Directive[Bold, RGBColor["#ac3b61"], DotDashed, Medium]]}], 
Graphics[{Text["--P=0.75", {0.2, 4}, TextStyle -> Directive[Bold, 
RGBColor["#edc7b7"], Medium]]}], Graphics[{Text["--P=0.9", {0.2, 3.5}, 
TextStyle -> Directive[Bold, RGBColor["#030a11"], Dotted, Medium]]}]]

enter image description here

To help you play with the code, I will attach the code to get the blue line, so you can run it with what you get for the blue one:

a = {{1.*10^-6, 0.}, {0.025001, 2.31442*10^-9}, {0.050001, 6198*10^-8},
{0.075001, 0.0000486898}, {0.100001, 0.00118944}, {0.125001, 
0.00795706}, {0.150001, 0.0279899}, {0.175001, 0.0683553}, {0.200001, 
0.133061}, {0.225001, 0.222841}, {0.250001, 0.33607}, {0.275001, 
0.469822}, {0.300001, 0.620694}, {0.325001, 0.785321}, {0.350001,
0.960656}, {0.375001, 1.14408}, {0.400001, 1.33343}, {0.425001, 
1.52695}, {0.450001, 1.72325}, {0.475001, 1.92128}, {0.500001, 2.1202},
{0.525001, 2.31938}, {0.550001, 2.51838}, {0.575001, 2.71684}, 
{0.600001, 2.91454}, {0.625001, 3.11129}, {0.650001, 3.30701}, 
{0.675001, 3.50161}, {0.700001, 3.69506}, {0.725001, 3.88736}, 
{0.750001, 4.07851}, {0.775001, 4.26853}, {0.800001, 4.45746}, 
{0.825001, 4.64532}, {0.850001, 4.83217}, {0.875001, 5.01803},
{0.900001, 5.20296}, {0.925001, 5.38699}, {0.950001, 5.57017},
{0.975001, 5.75254}, {1., 5.93414}}

plot = ListLinePlot[a, PlotRange -> {{0, 1}, {All, All}}, 
PlotStyle -> {Dashed, RGBColor["#123c69"]}, Frame -> True, 
Axes -> False, FrameLabel -> {OverHat[T], \[Kappa]}]
$\endgroup$
3
$\begingroup$

Use the 3-arg version of Text to specify the offset (I also changed the deprecated option TextStyle to the documented BaseStyle):

Show[
    plot,
    Graphics[{Text["--P=0", {0.2,5.5}, {-1,0},
        BaseStyle->Directive[Bold,RGBColor["#123c69"],Medium]]}],
    Graphics[{Text["--P=0.25", {0.2,5}, {-1,0},
        BaseStyle->Directive[Bold,RGBColor["#bab2b5"],Dashed,Medium]]}],
    Graphics[{Text["--P=0.5", {0.2,4.5}, {-1,0},
        BaseStyle->Directive[Bold,RGBColor["#ac3b61"],DotDashed,Medium]]}],
    Graphics[{Text["--P=0.75", {0.2,4}, {-1,0},
        BaseStyle->Directive[Bold,RGBColor["#edc7b7"],Medium]]}],
    Graphics[{Text["--P=0.9", {0.2,3.5}, {-1,0},
        BaseStyle->Directive[Bold,RGBColor["#030a11"],Dotted,Medium]]}]
]

enter image description here

$\endgroup$
0
$\begingroup$

Here is my approach.

 opt = {Bold, Medium, FontFamily -> "Helvetica"};

    legend = Column[{Style["--P=0", RGBColor["#123c69"], Evaluate@opt], 
    Style["\[LongDash]P=0.25", RGBColor["#bab2b5"], Evaluate@opt], 
    Style["\[Bullet]\[Dash]\[Bullet]P=0.5", RGBColor["#ac3b61"], 
     Evaluate@opt], 
    Style["\[LongDash]P=0.75", RGBColor["#edc7b7"], Evaluate@opt], 
    Style["\[Bullet]\[Bullet]\[Bullet]P=0.9", RGBColor["#030a11"], 
     Evaluate@opt]}, Alignment -> Left, Spacings -> {0, 0.5}];
ListLinePlot[a, PlotRange -> {{0, 1}, {All, All}}, 
 PlotStyle -> {Dashed, RGBColor["#123c69"]}, Frame -> True, 
 Axes -> False, FrameLabel -> {OverHat[T], \[Kappa]}, 
 Epilog -> Inset[legend, Scaled[{0.3, 0.7}]]]

enter image description here

$\endgroup$

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.