4
$\begingroup$

is it possible to insert a text outside the frame box?

I mean on the top left.

as shown in the following picture.

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ Plot[x, {x, 0, 1}, Frame -> True, Epilog -> Text[StringForm["x ``", 10^"-3"], {0.05, 1.05}], PlotRange -> {0, 1}, ImagePadding -> 20, PlotRangeClipping -> False] $\endgroup$
    – Bob Hanlon
    Oct 30 '20 at 17:26
  • $\begingroup$ @Bob Hanlon Thanks, but it this solution is not general, and it should be altered depending on the type of the plot $\endgroup$
    – user68857
    Oct 30 '20 at 17:46
  • $\begingroup$ For a more general solution used Scaled coordinates, e.g., Text[StringForm["x ``", 10^"-3"], Scaled[{0.07, 1.05}]] You should clarify what different types of plots to which you refer. $\endgroup$
    – Bob Hanlon
    Oct 30 '20 at 17:53
  • $\begingroup$ @Bob Hanlon Thank you very much $\endgroup$
    – user68857
    Oct 30 '20 at 17:55
  • 1
    $\begingroup$ You can also combine with graphics primitives using Show[{ your plot ,Graphics[{graphics primitives}]}]. For example Show[{Plot[{Log[x], 2 Log[x]}, {x, .1, 1.5}, AxesOrigin -> {0, 1}],Graphics[{White, Point[{-.2, 1.4}], Black, Text[StringForm["x``", 10^"-3"], {-.1, 1.3}]}]}, PlotRange -> All] $\endgroup$
    – Nicholas G
    Oct 30 '20 at 18:09
6
$\begingroup$
ClearAll[addLabel]
addLabel = Show[#, 
    Epilog -> Text[#2, Scaled[{0, 1}], {-1, -1}], 
    PlotRangeClipping -> False, ImagePadding -> 30] &;

Examples:

plt1 = Plot[x, {x, -1, 1}, Frame -> True, ImageSize -> Medium];
plt2 = Plot[ 3 Sin @ x, {x, -3 Pi, Pi}, Frame -> True, 
   AspectRatio -> 1, ImageSize -> Medium];
plt3 = ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}, ImageSize -> Medium];
plt4 = Histogram[RandomVariate[NormalDistribution[0, 1], 200], 
   Frame -> True, ImageSize -> Medium];
plt5 = RegionPlot[1/4 <= x^2 + y^2 <= 3, {x, -2, 2}, {y, -2, 2}, ImageSize -> Medium];
plt6 = BarChart[{1, 2, 3}, Frame -> True, ImageSize -> Medium];

plots = {plt1, plt2, plt3, plt4, plt5, plt6};

Multicolumn[addLabel[#, Style[Row[{"x", 10^"-3"}], 16]] & /@ plots, 3]

enter image description here

Use Text[#2, Scaled[{1, 1}], {1, -1}] to get:

enter image description here

Use Text[#2, Scaled[{1, 1}], {1, 1.5}, {0, 1}] to get:

enter image description here

Use Text[#2, Scaled[{1, 0}], {-1, 1.5}, {0, 1}] to get:

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.