PGFPlot 中的复合图

PGFPlot 中的复合图

我正在尝试pgfplots制作如下情节:

在此处输入图片描述

即,一个散点图,在 x 轴下方有第二个散点图。

我很难弄清楚这种图的名称(PGF 画廊似乎没有展示这个特定的例子)并且对于这种图表的技术名称以及如何使用它来制作它的任何帮助都pgfplots将非常感激。

答案1

在此处输入图片描述

MWEAsymptote(没有pgfplots,抱歉)。该inclusive fit函数是用近似曲线伪造的,但4-th order polynomial趋势曲线是自动计算的。

% cplot.tex :
\documentclass{article}
\usepackage[inline]{asymptote}
\begin{asydef}
struct Trend{
  real x[], y[];
  real xnorm[], ynorm[];
  int n;
  int degree;
  real xmin,xmax;
  real ymin,ymax;
  real xrange,yrange;
  string spoly;
  real[][] A;
  real[] b;
  real[] TrendCoeffs;
  real f(real x){
    real v=0;
    real t=(x-xmin)/xrange;
    for(int i=0;i<=degree;++i){
      v=v*t+TrendCoeffs[degree-i];
    }
    return v*yrange+ymin;
  } 

  void normalize(){
    xmin=min(x); xmax=max(x);
    ymin=min(y); ymax=max(y);
    xrange=xmax-xmin; yrange=ymax-ymin; 
    xnorm=map(new real(real i){return (x[(int)i]-xmin)/xrange;},sequence(n));
    ynorm=map(new real(real i){return (y[(int)i]-ymin)/yrange;},sequence(n));
  }

  void calcTrendCoeffs(){
    A=array(degree+1,array(degree+1,0.0));
    b=array(degree+1,0);
    A[0][0]=n;
    for(int i=1;i<=degree;++i){
      A[0][i]=sum(xnorm^i);
    }
    for(int i=1;i<=degree;++i){
      A[i][degree]=sum(xnorm^(i+degree));
    }
    for(int i=1;i<=degree;++i){
      for(int j=0;j<degree;++j){
        A[i][j]=A[i-1][j+1];
      }
    }

    b[0]=sum(ynorm);
    for(int i=1;i<=degree;++i){
      b[i]=sum(ynorm*xnorm^i);
    }
    TrendCoeffs=solve(A,b);
  };

  void operator init(real[] x,real[] y, int degree=2){
    this.x=copy(x);
    this.y=copy(y);
    this.degree=degree;
    this.n=x.length;
    assert(degree>1 && degree<7 && n>degree && y.length==n);
    normalize();
    calcTrendCoeffs();
  }
}
\end{asydef}
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
settings.outformat="pdf";
import graph;

pen trendPen=red+1.6bp+linetype(new real[]{2,2})+squarecap;
pen inclFitPen=deepblue+1.7bp+opacity(0.5);
pen markPen=brown;

defaultpen(fontsize(10pt));

real[] yTop={
1848,1817,1771,1618,1733,1641,1549,1587,1480,1511,1442,1411,1342,1357,1350,1258,
1273,1188,1165,1089,1073,1142,1112,1066,1020,1081,1066,1020,943,966,905,874,
805,882,797,790,767,721,698,698,721,667,652,613,675,606,590,552,
567,567,575,544,498,483,521,475,498,514,468,468,
};

real[] x=map(new real(real k){return 100.5+k;},sequence(yTop.length));

unitsize(25mm,0.02mm);

real xmin=100;
real xmax=160;
real ymin=0;
real ymax=2400;

frame mark; filldraw(mark,scale(2bp)*unitcircle,white,markPen+0.4bp);

draw(graph(x,yTop),nullpen,marker(mark),legend="\textsf{Data 2011 and 2012}");

Trend trend4=Trend(x,yTop,degree=4);
guide gTrend=graph(trend4.f,xmin,xmax);
guide gInclFit=
 subpath(gTrend,0,20*2)
 ..controls (x[26],yTop[26]+60) and (x[28],yTop[28]+40)
 ..subpath(gTrend,24*2,size(gTrend));

draw(gInclFit,inclFitPen
,legend="\textsf{Sig + Bkg inclusive fit ($\mathsf{m_{H} = 126.5}$ GeV)}");

draw(gTrend,trendPen,legend="\textsf{4-th order polynomial}");

string noTickLabels(real x){return "";};

xaxis(xmin,xmax,Ticks(ticklabel=noTickLabels,Step=10,step=2));
xaxis(XEquals(ymax),xmin,xmax,RightTicks(ticklabel=noTickLabels,Step=10,step=2));
yaxis(YEquals(xmin),ymin,ymax,RightTicks(Label(LeftSide),Step=200,step=50,beginlabel=false));
yaxis(YEquals(xmax),ymin,ymax,LeftTicks(ticklabel=noTickLabels,Step=200,step=50));

real y2min=-160;
real y2max=160;

real[] yBot;

for(int i=0;i<yTop.length;++i){
  yBot.push(yTop[i]-trend4.f(x[i]));
}

int yBotTicks=16;

real ystep=50;
real yStep=250;

xaxis(XEquals(ymin-yBotTicks*ystep),xmin,xmax
  ,LeftTicks(Label(RightSide),Step=10,step=2));

yaxis(YEquals(xmin),ymin-yBotTicks*ystep,ymin);
yaxis(YEquals(xmax),ymin-yBotTicks*ystep,ymin
  ,LeftTicks(ticklabel=noTickLabels,Step=yStep,step=ystep));

pair v;
for(int i=0;i<yBotTicks;++i){
  v=(xmin,ymin-i*ystep);
  ytick(v,size=ticksize);
}

ytick("$100$",(xmin,ymin-3*ystep),size=Ticksize);
ytick("$0$",(xmin,ymin-8*ystep),size=Ticksize);
ytick("$-100$",(xmin,ymin-13*ystep),size=Ticksize);

transform topXY(){
  transform t=shift(0,-8*ystep)*scale(1,50/20);
  return t;
}

draw(topXY()*graph(x,yBot),nullpen,marker(mark));

guide gTrendBot=topXY()*((xmin,0)--(xmax,0));

draw(gTrendBot,trendPen);

guide gInclFitBot=topXY()*((xmin,0)--(x[23],0))
 ..controls topXY()*(x[26],yBot[26]+60) and topXY()*(x[30],yBot[28]+40)
 ..topXY()*((x[30],0)--(x[x.length-1],0));

draw(gInclFitBot,inclFitPen);

size(300,300,(xmin,ymin-13*ystep),(xmax,ymax));

label(rotate(90)*"\textsf{Events / Gev}",(93,ymax),SW);
label(rotate(90)*"\textsf{Data - Bkg}",(93,0),SW);
label("\textsf{\textbf{\textit{ATLAS}}} \textsf{Preliminary}",(105,200),E);
label("$\mathsf{\sqrt{s}=7\,\mathsf{TeV} \displaystyle\int\! L\,dt = 4.8\,fb^{-1}}$",(130,1510),E);
label("$\mathsf{\sqrt{s}=8\,\mathsf{TeV} \displaystyle\int\! L\,dt = 5.9\,fb^{-1}}$",(130,1180),E);
label("\textsf{Selected diphoton sample}",point(N),4S);

add(legend(invisible),point((N+1.4E)),W);

shipout(bbox(Fill(paleyellow)));
\end{asy}
\end{figure}
\end{document}
%    
% Process:
%
% pdflatex cplot.tex
% asy cplot-*.asy   
% pdflatex cplot.tex

相关内容