2

I have a graph (a histogram and a draw(graph(...))). I want a sort of title label above the whole plot. Right now I'm manually placing it, but I will need to make many such graphs with different sizes. Is there any way to do this automatically?

Here is a simplified example:

import graph;
import stats;

string sample = "Participant G";
string key1 = "A";
string key2 = "B";
real[] a={152,136,151,144,512,128,184,152,136,128,152,128,568,120,144,144,160,136,128,1192,176,160,160,160,248,1624,488,296,408,143,161,167,144,145,152,128,2752,576,184,168,176,935,218,173,169,154,326,162,169,167,408,157,157,266,168,139,127,496,107,156,112,128,144,128,168,144,152,144,144,144,448,152,160,127,120,128,144,104,128,104,128,688,137,136,591,449,335,96,192,128,144,146,143,985,194,261,163,207,282,172,714,149,144,1249,155,1219,124,146,290,105,129,114,134,1270,2092,157,158,161,124,131,148,139,117,135,128,129,197,141,173,643,172,143,619,281,114,174,945,130,133,136,183,441,126,117,114,107,154,146,128,119,125,159,270,194,276,207,403,144,736,138,138,118,166,81,125,136,130,160,711,113,143,131,324,191,115,157,123,216,113,141,124,113,131,133,183,906,132,123,125,142,149,133,141,126,244,148,160,124,197,162,110,128,576,376,186,122,137,139,120,133,163,144,376,118,268,156,148,646,819,158,183,721,125,174,139,125,152,127,272,158,159,316,142,144,127,120,136,160,144,144,136,137,120,128,136,135,1320,471,641,190,705,161,134,99,309,154,136,641,155,147,2357,232,132,131,115,785,164,446,137,122,139,136,131,139,133,141,152,150,153,139,138,120,139,664,145,139,169,151,138,578,192,159,139,136,141,801,205,295,1113,194,924,136,141,151,159,144,369,1137,192,157,149,160,158,291,331,340,168,151,156,141,138,202,176,123,110,224,194,172,174,153,139,134,129,133,402,133,134,650,196,1038,159,1800,505,954,206,156,177,1424,236,136,141,143,123,120,170,123,220,157,139,136,120,127,138,1460,1329,748,138,578,249,345,185,163,341,136,333,151,123,118,108,114,102,118,120,131,131,152,175,146,696,144,191,1703,136,136,128,128,136,128,128,280,224,1552,1056,176,144,137,284,133,457,144,136,128,1279,200,1072,128,136,120,719,688,168,224,151,136,144,144,176,136,152,136,151,112,168,128,816,280,144,128,152,136,128,1472,240,176,177,752,144,136,152,120,144,152,112,128,120,120,96,120,144,112,160,136,136,160,1168,137,111,160,137,128,161,144,136,136,143,145,95,296,162,126,112,151,137};
int n = a.length;
int myBins=bins(a);

size(152mm,76mm,IgnoreAspect);

histogram(a,min(a),max(a),myBins,normalize=true,low=0,lightred,black,bars=false);

//manual placement, will break if data changes:
label(sample + ": " + key1 + "," + key2,(1000,.014),NE);
xaxis("time differences (ms)",BottomTop,LeftTicks);
yaxis("frequency",LeftRight,RightTicks(trailingzero));

What's the best way to do this? Can I put a label right above the top x-axis, or as a sort of second xaxis label?

2

There is a special function point which helps in cases like this. From asymptote.pdf:

The function

pair point(picture pic=currentpicture, pair dir, bool user=true);

is a convenient way of determining the point on the bounding box of pic in the direction dir relative to its center, ignoring the contributions from fixed-size objects (such as labels and arrowheads). If user is true the returned value is in user coordinates, otherwise it is in PostScript coordinates.

Thus to get a general solution, the label command from MWE with explicit coordinates

label(sample + ": " + key1 + "," + key2,(1000,.014),NE);

has to be changed to

label(sample + ": " + key1 + "," + key2,point(N),N);

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.