6

I was able to 'break' the vertical axis using pgfplots, but some issues came along with it:

  • Most importantly, I can't find how to add the 'break sign' (the two parallel lines) to my plot as well, and not only on the axes;
  • The legend is sticking to the upper axis;
  • The ylabel is no longer centred on the axis because I had to let it 'belong' to one of the two axes.

enter image description here

This is my code so far:

\documentclass{minimal}  
\usepackage{tikz}
\usepackage{pgfplots}
\tikzset{
    axis break gap/.initial=1mm
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    name=bottom axis,   
    legend cell align=left,
    width=13cm,
    height=7.86cm,
    xlabel = {golflengte (nm)},
    ylabel = {intensiteit (arbitraire eenheden)},
    xmin = 300, xmax = 550,
    ymin = 0, ymax = 55,
    ytick={0,10,20,30,40,50},
    grid = major,
    axis x line*=bottom
]
    \addplot[no marks, color=teal!80!black, line width=0.95
]
table[x=x_ex, y=y_ex]{Eu_em_ex.txt};

\end{axis}
\begin{axis}[
    at=(bottom axis.north),
    anchor=south, yshift=\pgfkeysvalueof{/tikz/axis break gap},
    width=13cm,
    height=3.3cm,
    xmin = 300, xmax = 550,
    ymin = 85, ymax = 100,
    ytick={90,100},
    grid = major,
    legend entries = {excitatiespectrum},
    axis x line*=top,
    xticklabel=\empty,
    after end axis/.code={
         \draw (rel axis cs:0,0) +(-2mm,-1mm) -- +(2mm,1mm)
              ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
              +(-2mm,-1mm) -- +(2mm,1mm)
              (rel axis cs:1,0) +(-2mm,-1mm) -- +(2mm,1mm)
              ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
              +(-2mm,-1mm) -- +(2mm,1mm);
         }]
\addplot[no marks, color=teal!80!black, line width=0.95
]
table[x=x_ex, y=y_ex]{Eu_em_ex.txt};            
\end{axis}
\end{tikzpicture}

\end{document}

The content of the file Eu_em_ex.txt:

x_em    y_em            x_ex        y_ex
500     1.73E-001       250     0.0942614858
501     1.03E-001       251     0.1122478006
502     5.22E-002       252     0.1259819159
503     1.27E-001       253     0.1244178886
504     6.10E-002       254     0.1612214076
505     1.40E-002       255     0.1334599218
506     5.82E-002       256     0.1684550342
507     1.43E-001       257     0.1643005865
508     2.24E-001       258     0.1713387097
509     5.99E-002       259     0.1960210166
510     1.33E-001       260     0.1735381232
511     5.31E-002       261     0.192844086
512     8.21E-002       262     0.2466075269
513     1.40E-001       263     0.2534501466
514     2.35E-001       264     0.2495889541
515     1.54E-001       265     0.2915244379
516     4.31E-001       266     0.3173797654
517     8.96E-001       267     0.3641539589
518     7.09E-001       268     0.4203611926
519     1.45E-001       269     0.4653269795
520     1.09E-001       270     0.5282790811
521     1.60E-001       271     0.5795987292
522     1.57E-001       272     0.6626876833
523     1.12E-001       273     0.6519349951
524     6.17E-002       274     0.7096085044
525     1.56E-001       275     0.7751021505
526     1.32E-001       276     0.7936749756
527     1.41E-001       277     0.8156691105
528     8.60E-002       278     0.9143983382
529     3.49E-002       279     0.9569203324
530     1.67E-001       280     1.0409868035
531     1.68E-001       281     0.994554741
532     1.48E-001       282     1.0927952102
533     1.27E-001       283     1.1436260997
534     2.66E-001       284     1.1265195503
535     2.32E-001       285     1.178327957
536     2.29E-001       286     1.1793054741
537     1.45E-001       287     1.2550630499
538     1.15E-001       288     1.2320913978
539     1.30E-001       289     1.1372722385
540     2.56E-001       290     1.1978782991
541     1.83E-001       291     1.2022771261
542     4.73E-001       292     1.2027658847
543     1.90E-001       293     1.1382497556
544     6.04E-002       294     1.1964120235
545     3.77E-002       295     1.1988558162
546     1.80E-001       296     1.1617101662
547     5.34E-002       297     1.1661089932
548     7.31E-002       298     1.2208499511
549     1.89E-001       299     1.7873211144
550     1.04E-001       300     1.3303318671
551     4.22E-002       301     1.1573113392
552     1.36E-001       302     1.2110747801
553     1.23E-001       303     1.4510552297
554     2.49E-001       304     2.4334599218
555     2.56E-001       305     1.6910356794
556     1.22E-001       306     1.9720718475
557     1.99E-001       307     1.9139095797
558     1.90E-001       308     1.5688460411
559     1.00E-001       309     1.4388362659
560     4.54E-002       310     1.4095107527
561     1.08E-001       311     1.3401070381
562     1.77E-001       312     1.7755909091
563     1.78E-001       313     1.4026681329
564     1.37E-001       314     1.1763729228
565     1.70E-001       315     1.1172331378
566     1.09E-001       316     1.2838998045
567     1.95E-001       317     2.0659134897
568     6.90E-002       318     2.3880053763
569     1.35E-001       319     10.0463631476
570     1.14E-001       320     2.7008108504
571     1.86E-001       321     2.6426485826
572     8.94E-002       322     2.5600483871
573     8.51E-002       323     2.5136163245
574     1.20E-001       324     1.9618079179
575     1.15E-001       325     1.2130298143
576     2.06E-001       326     1.1387385142
577     1.74E-001       327     1.5268128055
578     3.46E-001       328     2.0307228739
579     6.32E-001       329     1.5708010753
580     9.78E-001       330     0.847927175
581     2.71E-001       331     0.6841930596
582     3.08E-001       332     0.4921109482
583     4.84E-001       333     0.429012219
584     6.10E-001       334     0.358044477
585     6.67E-001       335     0.3336554252
586     9.72E-001       336     0.289471652
587     1.36E+000       337     0.2564804497
588     1.65E+000       338     0.2380542522
589     4.37E+000       339     0.1991979472
590     6.28E+000       340     0.1808206256
591     6.70E+000       341     0.1417199413
592     7.44E+000       342     0.1476339198
593     6.85E+000       343     0.1522282502
594     5.90E+000       344     0.1325801564
595     6.16E+000       345     0.1200679374
596     4.35E+000       346     0.1109281525
597     3.02E+000       347     0.1276925709
598     1.81E+000       348     0.1303807429
599     1.23E+000       349     0.2639584555
600     7.20E-001       350     0.2034012708
601     8.96E-001       351     0.3118567937
602     8.79E-001       352     0.3441637341
603     1.08E+000       353     0.2186016618
604     1.55E+000       354     0.1772526882
605     2.83E+000       355     0.2554540567
606     4.69E+000       356     0.2951412512
607     5.90E+000       357     0.4102927664
608     8.04E+000       358     0.5248577713
609     6.64E+000       359     0.5253465298
610     1.09E+001       360     0.6876143695
611     2.83E+001       361     2.9789144673
612     6.43E+001       362     15.1099017595
613     7.46E+001       363     19.7726583578
614     6.71E+001       364     1.6871256109
615     9.85E+001       365     1.4559428152
616     9.99E+001       366     2.7834110459
617     4.68E+001       367     6.0189926686
618     2.15E+001       368     3.3054051808
619     1.16E+001       369     1.4266173021
620     1.06E+001       370     0.7751021505
621     1.10E+001       371     0.8528147605
622     8.91E+000       372     1.0028636364
623     8.74E+000       373     1.994554741
624     5.53E+000       374     6.3660112414
625     3.89E+000       375     7.8127365591
626     2.54E+000       376     9.28878739
627     2.21E+000       377     16.9476339198
628     2.15E+000       378     8.1011041056
629     1.44E+000       379     7.4559428152
630     1.53E+000       380     12.0258352884
631     1.25E+000       381     14.9828245357
632     1.91E+000       382     18.2770571848
633     1.19E+000       383     15.2076534702
634     7.50E-001       384     12.1724628544
635     7.41E-001       385     16.9280835777
636     7.49E-001       386     10.7550630499
637     4.94E-001       387     7.3386407625
638     5.88E-001       388     5.0903514174
639     5.14E-001       389     3.7022771261
640     7.29E-001       390     2.5967052786
641     9.22E-001       391     2.1128343109
642     3.49E-001       392     2.6563338221
643     1.74E+000       393     5.2272038123
644     1.24E+000       394     26.380673998
645     1.51E+000       395     99.9974872923
646     7.87E-001       396     15.3933817204
647     1.17E+000       397     14.7531080156
648     6.78E-001       398     11.1607326491
649     1.21E+000       399     6.6397160313
650     1.94E+000       400     7.7443103617
651     1.46E+000       401     7.7443103617
652     1.34E+000       402     3.8611236559
653     2.48E+000       403     1.642159824
654     3.39E+000       404     0.8953367546
655     3.21E+000       405     0.7325801564
656     1.42E+000       406     0.7892761486
657     8.55E-001       407     0.6455811339
658     4.47E-001       408     0.5815537634
659     6.10E-001       409     0.4554051808
660     4.16E-001       410     0.490155914
661     2.39E-001       411     0.7804784946
662     1.39E-001       412     0.3224139785
663     2.69E-001       413     0.4706544477
664     4.25E-001       414     0.8743201369
665     2.54E-001       415     2.6289633431
666     1.62E-001       416     5.2565293255
667     4.18E-001       417     4.4388362659
668     4.35E-001       418     2.985757087
669     2.68E-001       419     1.9867346041
670     9.78E-002       420     0.6504687195
671     6.22E-002       421     0.1878587488
672     2.60E-002       422     0.0831666667
673     2.32E-001       423     0.0567248289
674     3.64E-001       424     0.0503709677
675     3.43E-001       425     0.0488069404
676     3.99E-001       426     0.142159824
677     3.11E-001       427     0.1027658847
678     6.22E-001       428     0.1928929619
679     2.91E-001       429     0.1055518084
680     6.21E-001       430     0.047927175
681     6.13E-001       431     0.0941637341
682     3.29E-001       432     0.0599995112
683     1.65E-001       433     0.0168861193
684     1.26E+000       434     0.0050239492
685     4.68E-001       435     0.0012292278
686     5.59E-001       436     0.0005733138
687     9.39E-001       437     0.0025117302
688     1.11E+000       438     0.0006959922
689     9.28E-001       439     0.0006212121
690     1.64E+000       440     0.0006510264
691     1.59E+000       441     0.0018826979
692     3.51E+000       442     0.0048675464
693     3.86E+000       443     0.0042468231
694     3.78E+000       444     0.0070327468
695     3.59E+000       445     0.0462116325
696     4.17E+000       446     0.1756886608
697     3.83E+000       447     0.1239780059
698     4.59E+000       448     0.2004687195
699     3.46E+000       449     0.251983871
700     4.35E+000       450     0.2447013685
701     1.28E+001       451     0.1481226784
702     1.60E+001       452     0.0526192571
703     9.45E+000       453     0.0310454545
704     8.06E+000       454     0.0296476051
705     4.72E+000       455     0.0568225806
706     2.54E+000       456     0.1658646139
707     1.51E+000       457     0.2763240469
708     1.08E+000       458     0.3389340176
709     8.05E-001       459     0.3150337243
710     2.61E-001       460     0.3487580645
711     3.01E-001       461     0.5101950147
712     4.50E-001       462     0.7824335288
713     1.36E+000       463     1.453987781
714     2.96E-001       464     2.6929907136
715     4.13E-001       465     53.0277903226
716     1.72E-001       466     10.0219252199
717     7.87E-002       467     2.4275948192
718     2.16E-001       468     0.8845840665
719     4.34E-001       469     0.3355615836
720     1.64E-001       470     0.3051119257
721     1.87E-001       471     0.3666466276
722     4.14E-001       472     0.627985826
723     3.08E-002       473     0.7061871945
724     3.45E-001       474     0.8904491691
725     2.02E-001       475     0.5620034213
726     3.34E-001       476     0.4044276637
727     5.54E-001       477     0.308728739
728     4.96E-001       478     0.1094618768
729     4.07E-002       479     0.0466564027
730     5.97E-001       480     0.0316026393
731     1.26E+000       481     0.039872434
732     1.83E-001       482     0.050957478
733     5.31E-001       483     0.0678685239
734     3.29E-001       484     0.0641539589
735     6.16E-001       485     0.0861480938
736     2.54E+000       486     0.2611725318
737     4.43E-001       487     0.4420620723
738     1.32E-001       488     0.1892272727
739     1.35E-001       489     0.347242913
740     3.64E-001       490     0.1708499511
741     1.16E-001       491     0.093186217
742     1.96E-001       492     0.1110747801
743     1.21E-001       493     0.0849261975
744     1.76E-001       494     0.0304100684
745     1.52E-001       495     0.0134843597
746     2.13E-002       496     0.0066368524
747     5.41E-001       497     0.0024384164
748     2.48E-002       498     0.0006911046
749     1.09E+000       499     0.0011495601
750     0.00E+000       500     0
751     2.30E-001       501     0.0025899316
752     2.92E-001       502     0.0065
753     6.24E-002       503     0.005498045
754     1.53E-001       504     0.0060014663
755     6.53E-003       505     0.0079613881
756     6.45E-001       506     0.0118372434
757     2.56E-001       507     0.0162800587
758     2.30E-001       508     0.0184941349
759     1.31E-002       509     0.0349750733
760     2.38E-001       510     0.0493445748
761     4.87E-002       511     0.0573602151
762     5.42E-001       512     0.0687482893
763     1.85E-001       513     0.0956788856
764     3.91E-001       514     0.1024726295
765     9.74E-001       515     0.1056006843
766     9.27E-002       516     0.0976827957
767     1.64E-001       517     0.0777903226
768     3.76E-001       518     0.0622478006
769     3.46E-001       519     0.04421261
770     6.00E-001       520     0.0371940371
771     3.19E-001       521     0.0490513196
772     1.05E-001       522     0.0604393939
773     1.81E-001       523     0.1042321603
774     2.97E-001       524     0.1552096774
775     3.02E-001       525     0.2929907136
776     7.82E-002       526     2.6338509286
777     4.21E-002       527     2.5483181818
778     3.20E-001       528     0.378327957
779     8.67E-002       529     0.4002243402
780     7.76E-001       530     0.5194814272
781     2.14E-001       531     0.7540855327
782     1.35E-001       532     1.3371744868
783     5.43E-002       533     3.0180151515
784     2.26E-001       534     6.9183084066
785     1.54E-002       535     10.0805762463
786     5.79E-001       536     9.0248577713
787     6.18E-002       537     6.8352194526
788     3.73E-001       538     4.8489046921
789     2.00E-001       539     4.6876143695
790     2.50E-001       540     3.0556495601
791     2.55E-001       541     1.1460698925
792     8.67E-001       542     0.5219252199
793     5.50E-001       543     0.2726583578
794     5.12E-001       544     0.1688949169
795     6.68E-001       545     0.1251510264
796     5.80E-001       546     0.0966564027
797     6.40E-001       547     0.0780835777
798     4.11E+000       548     0.0719740958
799     3.53E-001       549     0.0592663734
800     1.95E+000       550     0.0706544477
4
3

This seems to work as is, but adding \pgfplotsset{compat=1.11} (or newer) breaks it.

  • To position the break sign, I first make a path along the top of the bottom axis, give both this and the plot a name with name path=<some name>, defined by the intersections library. The intersections between these two are found with \draw [name intersections={of=topline and lowerplot,name=i}], which makes the coordinates (i-1) and (i-2). A line is drawn relative to the midpoint between the those points with ($(i-1)!0.5!(i-2)$) +(-2mm,0) -- +(2mm,0), and similar for the second line.

  • The ylabel is positioned manually relative to the corners of the axes.

  • You can move the legend a bit downwards with legend style={yshift=-2pt}.

enter image description here

\documentclass[border=4mm]{standalone}  
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\usepackage{pgfplots}
\tikzset{
    axis break gap/.initial=1mm
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    name=bottom axis,   
    legend cell align=left,
    width=13cm,
    height=7.86cm,
    xlabel = {golflengte (nm)},
    xmin = 300, xmax = 550,
    ymin = 0, ymax = 55,
    ytick={0,10,20,30,40,50},
    grid = major,
    axis x line*=bottom,
    clip mode=individual
]
    \addplot[no marks, color=teal!80!black, line width=0.95,name path=plot]
table[x=x_ex, y=y_ex]{Eu_em_ex.txt};
\path [name path=topline] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax}) --
  (axis cs:\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
\draw [name intersections={of=topline and plot,name=i}] 
  ($(i-1)!0.5!(i-2)$) +(-2mm,0) -- +(2mm,0)
  ($(i-1)!0.5!(i-2) + (0,\pgfkeysvalueof{/tikz/axis break gap})$) +(-2mm,0) -- +(2mm,0);
\end{axis}
\begin{axis}[
    at=(bottom axis.north),
    name=top axis,
    anchor=south, yshift=\pgfkeysvalueof{/tikz/axis break gap},
    width=13cm,
    height=3.3cm,
    xmin = 300, xmax = 550,
    ymin = 85, ymax = 100,
    ytick={90,100},
    grid = major,
    legend entries = {excitatiespectrum},
    legend style={yshift=-3pt},
    axis x line*=top,
    xticklabel=\empty,
    after end axis/.code={
         \draw (rel axis cs:0,0) +(-2mm,-1mm) -- +(2mm,1mm)
              ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
              +(-2mm,-1mm) -- +(2mm,1mm)
              (rel axis cs:1,0) +(-2mm,-1mm) -- +(2mm,1mm)
              ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
              +(-2mm,-1mm) -- +(2mm,1mm);
         }]
\addplot[no marks, color=teal!80!black, line width=0.95]
table[x=x_ex, y=y_ex]{Eu_em_ex.txt}; 
\end{axis}
\path (bottom axis.south west -| bottom axis.outer south west) -- node[anchor=south,rotate=90]{intensiteit (arbitraire eenheden)} (top axis.north west -| top axis.outer north west);

\end{tikzpicture}

\end{document}

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.