我有一张图表(ahistogram
和 a draw(graph(...))
)。我想要在整个图上方添加一种标题标签。现在我正在手动放置它,但我需要制作许多不同大小的此类图表。有没有办法自动完成此操作?
以下是一个简化的示例:
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));
最好的方法是什么? 我可以将标签放在顶部 x 轴的正上方吗,或者将其作为第二个 x 轴标签?
答案1
有一个特殊功能point
可以解决此类情况。来自asymptote.pdf
:
功能
pair point(picture pic=currentpicture, pair dir, bool user=true);
是确定边界框上 相对于其中心
pic
方向的点的便捷方法dir
,忽略固定大小对象(如标签和箭头)的影响。如果 user 为 true,则返回值位于用户坐标中,否则位于PostScript
坐标中。
因此,为了得到一个通用解决方案,label
命令来自MWE
明确的坐标
label(sample + ": " + key1 + "," + key2,(1000,.014),NE);
必须改为
label(sample + ": " + key1 + "," + key2,point(N),N);