Quantcast
Channel: Question and Answer » pgfplots
Viewing all 125 articles
Browse latest View live

Depressed last plot in pgfplots

$
0
0

For some reason, the rightmost graph is slightly lower than the other graphs, but I don’t know why.

Code:

documentclass[12pt]{article}
usepackage{amsmath, amssymb}
usepackage[usenames,dvipsnames,svgnames]{xcolor}
usepackage{tikz}
usetikzlibrary{positioning,calc}
usepackage{pgfplots}

begin{document}

begin{center}
setlength{tabcolsep}{1em}
begin{tabular}[ht]{m{8em} m{8em} m{8em} m{8em}}

begin{tikzpicture} %y=x

begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=(x),ylabel=(y),
samples=2]

addplot[domain=-2:2,<->,>=latex] {x};

end{axis}

end{tikzpicture}

&
begin{tikzpicture} %y=x^2

begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=(x),ylabel=(y),
samples=200]

addplot[domain=-1.732:1.732,<->,>=latex] {x^2};

end{axis}
end{tikzpicture}

&
begin{tikzpicture} %y=x^3

begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-2,ymax=2,ytick={-1,1},
xlabel=(x),ylabel=(y),
samples=200]

addplot[domain=-1.260:1.260,<->,>=latex] {x^3};

end{axis}
end{tikzpicture}

&
begin{tikzpicture} %y=x^4

begin{axis}[grid=both,
axis lines=middle,
ticklabel style={fill=white,font=scriptsize},
x=0.8cm,y=0.8cm,clip=false,
xmin=-2,xmax=2,xtick={-1,1},
ymin=-1,ymax=3,ytick={1,2},
xlabel=(x),ylabel=(y),
samples=200]

addplot[domain=-1.316:1.316,<->,>=latex] {x^4};

end{axis}
end{tikzpicture}
end{tabular}
end{center}

end{document}

This yields the following image.


Pgfplots not working with Pgfplotstable

$
0
0

I am writing a document using LaTeX which must contain both graphs and tables. For the graphs I have been using pgfplots and this has worked brilliantly. Now I needed to insert a few tables and was trying to do so using pgfplotstable, however, the moment I add usepackage{pgfplotstable} to the document I am getting the following error:

“! Package pgfplots Error: This style is supposed to be constant..”

Does anyone have any idea why I am getting this error and what I can do to fix it?

documentclass[10pt,a4paper]{report} 
usepackage{amsmath} 
usepackage{amsfonts} 
usepackage{amssymb} 
usepackage{graphicx} 
usepackage{color} 
graphicspath{ {images/} } 
usepackage{Pgfplots} 
usepackage[backend=bibtex]{biblatex} 
usepackage{pgfplotstable} 
usepackage{booktabs} 
bibliography{Biblog.bib} 
begin{document}

PGFPlots polaraxis axis labels are swapped (or in the wrong place)

$
0
0

I have some problems with axis labels when using the polar axis, if I set the X and Y label they appear in the wrong place.

When using the polar axis;

  • x coordinate is the angle (azimuth, phi)
  • y coordinate is the radius (zenith, theta).

However, the xlabel is printed where one would expect it to be in a cartesian plot, except that that is now the y axis (using TeXLive 2015, PGFPlots v1.12.1).
Similar for the y label is is located where the y axis would be in a cartesian plot, except that is it rotated.

Here I used:

xlabel={Azimuth [rad] (x-label)},
xlabel style={red},
ylabel={Zenith [rad] (y-label)},
ylabel style={blue},

This is how it looks in TeXLive 2015, PGFPlots v1.12.1:

polar_bug_2015

This is how it looks in TeXLive 2013/2014, PGFPlots v1.8/v1.10:

polar_bug_2013_2014

Using some shifts and rotations we get it to look nice, however, those shifts are different for TeXLive 2013-2014 and 2015:

shifted_labels

This did require some ugly hacks, for the xlabel:

coordinate (xlabel) at ([rotate=-45, yshift=1.5cm] xticklabel* cs: 0);
node[rotate=-45] at (xlabel) { {{ xlabel }} };

The ylabel value is simply entered as xlabel and then shifted with the axis line, but that does not work for 2013/2014.

Should we resort to version detection to make it work in all versions?
And will this be fixed in the next PGFPlots?
(We created a Python package for plotting which outputs plots as TeX using PGFPlots, so compatibility with older versions would be nice.)

How to draw this image using tikz?

$
0
0

enter image description here

Beyond the solution to this particular diagram, can you explain if there is a general set of steps that you would follow to obtain this code?

My guesses: Would conversion to vector graphics give some guidelines?

Are there parts of the process that can be automated?
Etc.

I tried: Using Inkscape to convert to vector graphics and somehow get a bunch of coordinates that I could use as a guideline for the tikz code.

I got the following so far (I took some code from this answer):

documentclass{article}
usepackage{pgfplots}
usetikzlibrary{decorations.text}

pgfmathdeclarefunction{gauss}{3}{%
pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

begin{document}‎‎

begin{tikzpicture}
draw[draw=none](0,4)--node[anchor=center, above] (A) {Marginal
distribution of Brownian motion through time} (10,4) ;
draw[->,very thick](0,0)--(0,4) node[anchor=south, above left,
rotate=90] {Spacial distribution};
draw[->,very thick](0,0)-- node[anchor=north, below] {Time} (10,0);
draw[dotted, domain=0:9,samples=35,thick] plot ({x+0.5},
{sqrt(x)/2+2});
draw[dotted, domain=0:9,samples=35, thick, smooth, postaction=
{decorate, decoration={raise=-10pt, text along path,text 
align=center,text={Spread of Willow Tree}}}] plot ({x+0.5},
{-sqrt(x)/2+2});
draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(x, 1, 1)+1},
{x+1}) node (B) {};
draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(x, 1, 0.5)+3},
{x+1}) node (C) {};
draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(x, 1, 0.25)+5},
{x+1}) node (D) {};
draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(x, 1, 0.2)+7},
{x+1}) node (E) {};
draw[->] (A) to (B);
draw[->] (A) to (C);
draw[->] (A) to (D);
draw[->] (A) to (E);
end{tikzpicture}

end{document}

which produces:

enter image description here

Crop z-axis of PGFPlots

$
0
0

I try to implement the following image of the function 1/(x*y) I plotted using WolframAlpha using the PGFPlots package:

This is how it should look like

The function is not defined if x=0 or y=0, so I split it up into four parts like this:

begin{tikzpicture}
    begin{axis}[zmin=-20,zmax=20]
            addplot3[surf,domain=-1:-0.1,y domain=0.1:1]{1/(x*y)};
            addplot3[surf,domain=0.1:1,y domain=-1:-0.1]{1/(x*y)};
            addplot3[surf,domain=-1:-0.1,y domain=-1:-0.1]{1/(x*y)};
            addplot3[surf,domain=0.1:1,y domain=0.1:1]{1/(x*y)};
    end{axis}
end{tikzpicture}

This is how the result looks like:

my try

Without the [zmin=-20,zmax=20] after begin{axis} one cannot see that the values grow very large close to the x-axis and y-axis as easily as in the image from WolframAlpha. This is because the first image crops the values of the function at -20 and 20. Adding [zmin=-20,zmax=20] after begin{axis} however still draws bigger values of the function if their projection is in the bounding box, which looks really strange.

How can I avoid this and reproduce the image of WolframAlpha?

Thanks for your help!

Displaying significance of results in pgfplots by lines with asteriks

$
0
0

after searching for some time without finding a satisfying answer, I finally decided to post my first question. Using the search function, I found simmilar questions, but non of the answer given there where satisfying either.

My problem:
I am using pgfplots to display results in bar graphs and tested the data for significant differences by ANOVA and Dunnett’s Multiple Comparison Test vs. one control. I would like to have something, that looks like this:

enter image description here

I produced this using the following code:

documentclass{scrartcl}%
usepackage[T1]{fontenc}%
usepackage[utf8]{inputenc}%
usepackage[ngerman]{babel}%

usepackage{amsmath}%
usepackage{tikz}%
usepackage{pgfplots}%
pgfplotsset{width=7cm,compat=1.7}%

begin{document}%
begin{tikzpicture}%
begin{axis}[%
    ybar,%
    title=Test,%
    axis y line=left, axis x line*=bottom,%
    ymin=0, ymax=70,%
    x tick label style={rotate=45,anchor=east},%
    symbolic x coords={A, B, C, D, E},%
    ylabel=difference in %,%
        ]%
addplot+[%
    color=black,%
    error bars/.cd,%
    y dir=both,%
    y explicit,%
        ]%
table[%
    y error=err%
        ] {barexample.txt};%

addplot[black, sharp plot]%
    coordinates {(A,50) (D,50)}%
    node[above] at (150,500) {***}%
    ;%

addplot[black, sharp plot]%
    coordinates {(A,60) (E,60)}%
    node[above] at (150,600) {**}%
    ;%
end{axis}%
end{tikzpicture}%
end{document}%

This ist the content of the datafile:

xval    yval    err     sig 
A       1       0.2     control
B       10      2.5     n.s.
C       20      2.2     n.s.
D       40      4.2     ***
E       28      2.8     **

I am looking for a solution, that would check the sig collum for the asteriks and given the case there are *** or ** or * draws a line above the colums and inserts the appropriated numer of * at a certain position of the line. In addition, lines should be stacked, starting with the far right on top and so on.

Thank you for your help!

TikZpicture/pgfplots: How to insert time-data in mm:ss-format (without hh:) into x-axis?

$
0
0

Imagine an ordinary x/y-diagram by using the pgfplots/tikzpicture-packages:

In case of regular date-values (dd-mm-yyyy) usually there is no problem in application. But now, I have to add times-values in the format of mm:ss (minute:second) without hours (hh:) into the x-axis. How can I solve that?


Minimum Working Example (MWE):

documentclass{scrartcl}

usepackage{pgfplots}

begin{document}

begin{tikzpicture}

begin{axis}[
%------------------------------------------------------------------------------
%   date coordinates in = x,                     % set X-axis as date-axis
    xmin = 0,                                    % minimum-value of X
    xmax = 60,                                   % maximum value of X
    ymin = 0,                                    % minimum-value of Y
    ymax = 2200,                                 % maximum-value of Y
    xlabel={time [min]},                         % caption of X-axis
    ylabel = {pressure [mm H2O]},                % caption of Y-axis
%------------------------------------------------------------------------------
    ]
%------------------------------------------------------------------------------
    addplot plot coordinates {(0,0)(60,2000)};  % just to show some line
%   addplot table[x=time,y=pressure]{data.txt}; % the "real" data
%------------------------------------------------------------------------------
end{axis}

end{tikzpicture}

end{document}

For example, the belonging data-table data.txt looks like that:

time    pressure
00:00   -3
00:01   50
00:01   170
01:02   300
02:02   500
03:03   700
04:03   750
05:04   800
10:04   1100
01:05   1200
18:05   1300
19:06   1400
20:06   1500
00:07   1600
30:07   1700
40:08   1800
50:08   1900
55:09   2000
59:09   2000
60:00   2000

How can I add such a time-format inside diagram’s x-axis)? Setting date coordinates in = x didn’t bring the solution for me – maybe seconds are not accepted as a date…


Edit: Maybe this could be an approach?

begin{filecontents}{mydata.csv}
X   Y1
 00:00.0   25
 00:00.5   25
 00:01.0   25.2
 00:01.5   25.7
 00:02.0   26.7
 00:02.5   27.7
 00:03.0   28.7
 00:03.5   29.7
 00:04.0   30.6
 00:04.5   31.6
 00:05.0   32.6
 00:05.5   33.6
 00:06.0   34.4
 00:06.5   35.4
 00:07.0   36.3
 00:07.5   37.2
 00:08.0   38.1
 00:08.5   38.9
 00:09.0   39.7
 00:09.5   40.5
 00:10.0   41.3
end{filecontents}

begin{filecontents}{mylabel.csv}
X
 00:00.0
 00:01.0
 00:02.0
 00:03.0
 00:04.0
 00:05.0
 00:06.0
 00:07.0
 00:08.0
 00:09.0
 00:10.0
end{filecontents}

documentclass[paper=a4,parskip]{scrartcl}
usepackage{pgfplots}
pgfplotsset{compat=1.9}
pgfplotsset{/pgf/number format/use comma}

begin{document}

    begin{figure}
       centering
       begin{tikzpicture}
       begin{axis}[width=0.6textheight,      
       height=0.4textheight,
       xlabel={Time [mm:ss.0]},
       ylabel={Temperature [Celsius]},
       ymajorgrids,
       xtick={0,2,...,100},
       xticklabels from table={mylabel.csv}{X},,
       xticklabel style={rotate=45,anchor=east},
       legend pos=outer north east,
       legend cell align=left,
       legend style={draw=none}]
       addplot[color=black,mark=none] table [x expr=coordindex,y=Y1] {mydata.csv};
       legend{Graph}
       end{axis}
       end{tikzpicture}
    end{figure}
end{document}

Screenshot of the result:

enter image description here


Unfortunately, I get different errors when changing the mm:ss:0-format into my desired mm:ss-format…

Combine multiple pgfplots from tex files

$
0
0

I have been using Sharelatex to write my thesis and I have accumulated many pgfplots. I can’t include more than ~6 pgfplots produced by csv files before I get compile time out. I have been dividing my plots among several tex files. Is there a way to combine all of it together in the end in a simple fashion? I tried searching and seems like one option is to convert pdf files to pngs and add the plots as images, but I lose the quality and sharpness of the figure (I tried imagemagick and was not happy with the output). What are my options, please advise. Thanks.

Here is one groupplot of many (as an example):

documentclass{standalone}
usepackage[utf8]{inputenc}
usepackage{graphicx}
usepackage{floatrow}
usepackage{tikz}
usepackage{pgfplots}
usepackage{fixltx2e}
usepackage{siunitx}
usepackage{lscape}
usepackage{diagbox}
usepackage{caption}
usepackage{xcolor}
usepackage[version=4]{mhchem}
usepackage{subcaption}
usepgfplotslibrary{groupplots}
DeclareSIUnit{molar}{M}
pgfplotsset{compat=newest}



begin{document}

begin{figure}[h]
setlength{abovecaptionskip}{15pt plus 3pt minus 2pt}
begin{minipage}{columnwidth}
centering
begin{tikzpicture}[scale = .65, transform shape,trim left]    
begin{groupplot}[
group style={
group size=2 by 3,
horizontal sep=0pt,
vertical sep=50pt
},
    scale only axis,
    xlabel={nm},
    ylabel={Abs},
    xmin=385, xmax=565, 
    xtick pos=left,
    ytick pos=left,
    no marks,
    max space between ticks=1000pt,
    try min ticks=4,
    xlabel={},
    ylabel={}
]

nextgroupplot[title=textbf{(a)} $15:60$ (TPPStextsubscript{4}-ce{2Cl}:Lig{1})]
addplot  table [col sep=comma, x=nm, y=10] {ST053 1560 Por SG.csv};label{1560porsg1} 
addplot  table [col sep=comma, x=nm, y=100] {ST053 1560 Por SG.csv};label{1560porsg2}
addplot  table [col sep=comma, x=nm, y=200] {ST053 1560 Por SG.csv};label{1560porsg3}

nextgroupplot[title=textbf{(e)} $60:15$ (TPPStextsubscript{4}-ce{2Cl}:Lig{1})]
addplot  table [col sep=comma, x=nm, y=10] {ST053 6015 Por SG.csv};
addplot  table [col sep=comma, x=nm, y=100] {ST053 6015 Por SG.csv};
addplot  table [col sep=comma, x=nm, y=200] {ST053 6015 Por SG.csv};

nextgroupplot[title=textbf{(g)} $60:15$ (TPPStextsubscript{4}-ce{2Cl}:Buffer)]
addplot table [col sep=comma, x=nm, y=10] {ST053 6015 Por blank SG.csv};
addplot table [col sep=comma, x=nm, y=100] {ST053 6015 Por blank SG.csv};
addplot table [col sep=comma, x=nm, y=200] {ST053 6015 Por blank SG.csv};

end{groupplot}
node at ($(group c1r2.west)!0.5!(group c1r2.west)$)[xshift=-1.5cm]{rotatebox{90}{large{Absorption}}};
node at ($(group c1r3.south)!0.5!(group c2r3.south)$)[yshift=-1.5cm]{large{Nanometer}};
end{tikzpicture}
end{minipage}
caption{Caption}
end{figure}

end{document}

pgfplots: How to adjust the width of the drawing area?

$
0
0

I want to produce plots that fit into the columns of a text document. My problem is that setting width=linewidth seems to apply on the axis and labels only. When I put the legend outside it sticks out of the column:
enter image description here

I would like to get this:

enter image description here

In this case I have adjusted the width manually to fit the drawing area into the column (see code below).

Is there a way to achieve this automatically?

documentclass[twocolumn]{article}
usepackage[english]{babel}
usepackage{blindtext}

usepackage{pgfplots}
pgfplotsset{compat=1.11}
usetikzlibrary{backgrounds}

begin{document}
%%% The following figure fits well %%%
begin{figure}
  begin{tikzpicture}[show background rectangle,tight background]
  begin{axis}[
    width = linewidth,
    xlabel=x axis label,
    ylabel=y axis label,
    legend pos = {north west},
  ]
  addplot[blue] {exp(x)};addlegendentry{legend entry}
  end{axis}
  end{tikzpicture}
caption{This figure is part of a two column document and fits perfectly}
end{figure}
blindtext
%%% The next figure is to large %%%
begin{figure}
  begin{tikzpicture}[show background rectangle,tight background]
  begin{axis}[
    width = linewidth,
    xlabel=x axis label,
    ylabel=y axis label,
    legend pos = {outer north east},
  ]
  addplot[red] {exp(x)};addlegendentry{legend}
  end{axis}
  end{tikzpicture}
caption{Putting the legend outside the axis box leads to this unpleasant behavior.}
end{figure}
blindtext[5]
%%% The next figure is adjusted to fit %%%
begin{figure}
  begin{tikzpicture}[show background rectangle,tight background]
  begin{axis}[
    width = 0.76linewidth, % This value only works for this plot
    xlabel=x axis label,
    ylabel=y axis label,
    legend pos = {outer north east},
  ]
  addplot[red] {exp(x)};addlegendentry{legend}
  end{axis}
  end{tikzpicture}
caption{In this case the width has been adjusted manually so that plot and legend fit into the column.}
end{figure}
blindtext[5]
end{document}

pgfplots' fill between with wrong segment split

$
0
0

I want the last segment to be white, but it seems that the last segment is
combined with the previous segment.

enter image description here

documentclass{article} 
usepackage{tikz}
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
pgfmathdeclarefunction{vdw}{0}{pgfmathparse{8.314*115/(x-0.0000364)-0.1358/x/x}}

begin{document}
begin{tikzpicture}
  begin{axis}[
    axis y line = left,
    axis x line = bottom,
    xlabel      = $V$,
    ylabel      = $P$,
    samples     = 500,
    domain      = 0.00005:0.0005,
    xmin = 0, xmax = 0.00055,
    ymin = 0, ymax = 5*10^6,
  ] 
  addplot[name path=vdw, black, thick, mark=none, ] {vdw}; 
  addplot[name path=line, gray, no markers, line width=1pt] {2.0*10^6}; 
  addplot fill between[ 
    of = vdw and line, 
    split, % calculate segments
    every segment no 0/.style={white},
    every segment no 1/.style={orange},
    every segment no 2/.style={red},
    every segment no 3/.style={white},
  ];
end{axis}

end{tikzpicture}
end{document}

Missing Legend Entries in GroupPlot

$
0
0

I am constructing a groupplot with a common legend placed in a node under the plot. An MWE that recreates my problem is below.

documentclass{article}
usepackage{pgfplots}
usepgfplotslibrary{groupplots}
usetikzlibrary{pgfplots.groupplots}

pgfplotsset{compat = 1.12}

begin{document}
    centering
    begin{figure}
    begin{tikzpicture}{fig3}
        begin{groupplot}[
            legend columns=4,
            legend entries={{tiny Hold All},{tiny Come and Go},{tiny Random},{tiny +Resources},{tiny ++Resources},{tiny ++ResourcesPT},{tiny ++ResourcesSM},{tiny ++ResourcesBM}},
            legend to name=Fig3Legend,
            group style={
                group name = fig3_plots,
                group size=3 by 1,
                xlabels at=edge bottom,
                ylabels at=edge left
            },
            width=textwidth,
            legend style={draw=none},
            xlabel = {footnotesize $alpha$},
            ylabel = {footnotesize Avg Portfolio Value},
        ]
        nextgroupplot[title={scriptsize +Resources},
            y tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
      },
            footnotesize,
            x tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
    },
        ymin=0,
        xtick={1000,2000,3000,4000}]
            addplot+[black, mark=o,line join=round, mark repeat=50] table[col sep=comma, y=HoldAll, x=Alpha]{ElicitedFixedAlpha.csv};
            addplot+[black, mark=x,line join=round, mark repeat=50] table[col sep=comma, y=ComeAndGo, x=Alpha]{ElicitedFixedAlpha.csv};
            addplot+[black, mark=|,line join=round, mark repeat=50] table[col sep=comma, y=Random, x=Alpha]{ElicitedFixedAlpha.csv};
            addplot+[black, mark=square,line join=round, mark repeat=50] table[col sep=comma, y=Plus, x=Alpha]{ElicitedFixedAlpha.csv};
        nextgroupplot[title={scriptsize ++Resources (Empirical CDF)},
            y tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
      },
            footnotesize,
            x tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
    },
        ymin=0]
            addplot+[black, mark=o,line join=round, mark repeat=50] table[col sep=comma, y=HoldAll, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=x,line join=round, mark repeat=50] table[col sep=comma, y=ComeAndGo, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=|,line join=round, mark repeat=50] table[col sep=comma, y=Random, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=square,line join=round, mark repeat=50] table[col sep=comma, y=PlusPlus, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
        nextgroupplot[title={scriptsize ++Resources (Elicited CDFs)},
            y tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
      },
            footnotesize,
            x tick label style={
                font=tiny,
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=0,
        /tikz/.cd
    },
        ymin=0]
            addplot+[black, mark=o,line join=round, mark repeat=50] table[col sep=comma, y=HoldAll, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=x,line join=round, mark repeat=50] table[col sep=comma, y=ComeAndGo, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=|,line join=round, mark repeat=50] table[col sep=comma, y=Random, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=triangle,line join=round, mark repeat=50] table[col sep=comma, y=PlusPlusPT, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=square,line join=round, mark repeat=50] table[col sep=comma, y=PlusPlusSM, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
            addplot+[black, mark=asterisk,line join=round, mark repeat=50] table[col sep=comma, y=PlusPlusBM, x=Alpha]{ElicitedFixedAlphaPlusPlus.csv};
        end{groupplot}
        node (fig3_Legend) at ($(fig3_plots c2r1.center)-(0,2.5cm)$){ref{Fig3Legend}};
    end{tikzpicture}
    caption{Fixed $alpha$ Values}
    label{FixedAlphas}
end{figure}
end{document}

The data is available at

ElicitedFixedAlpha.txt

ElicitedFixedAlphaPlusPlus.txt

It produces the following output

enter image description here

Which is fine, except that it’s missing the last two legend entries.

In the groupplot definition I have

legend entries={{tiny Hold All},{tiny Come and Go},{tiny Random},{tiny +Resources},{tiny ++Resources},{tiny ++ResourcesPT},{tiny ++ResourcesSM},{tiny ++ResourcesBM}},

But as you can see in the image, the last two aren’t there. The corresponding data series are in the chart…hard to see as they all land on top of each other in the rightmost chart, but they’re there. So why don’t the legend entries show up?

TikZpicture/pgfplots: How to reduce quantity of displayed xticklabels when using “xticklabels from table”?

$
0
0

I want to generate a simple x/y-diagram with data out of a data-table (~ 2000 values).


Minimum Working Example (MWE):

begin{filecontents}{Data_Table.csv}
X   Y
00:00   0
00:01   50
00:01   100
00:02   150
00:02   200
02:03   250
03:03   300
04:04   350
04:04   400
05:05   450
05:05   500
06:06   550
06:06   600
07:07   700
07:07   800
08:08   900
09:08   1000
12:09   1100
14:09   1200
14:10   1300
15:10   1400
16:11   1500
18:11   1600
20:12   1800
25:00   2000
end{filecontents}

documentclass{scrartcl}
usepackage{pgfplots}
pgfplotsset{compat=newest}

begin{document}

    begin{figure}
       begin{tikzpicture}
       begin{axis}[
       width=0.5textheight,      
       height=0.5textheight,
       xlabel={Time [mm:ss]},
       ylabel={Measurement [mm]},
       xtick=data,
       xticklabels from table={Data_Table.csv}{X},
       xticklabel style={rotate=90,anchor=east},
       xmin = 0,
       ymin = 0,
       ymax = 2200,
       legend pos=outer north east,
       legend cell align=left,
       legend style={draw=none}]
       addplot[color=black,mark=none] table [x expr=coordindex,y=Y] {Data_Table.csv};
       legend{Graph}
       end{axis}
       end{tikzpicture}
    end{figure}
end{document}

Screenshot of the result:

enter image description here


As you can see, there are far too many xticklabels displayed below the x-axis. How can I reduce the quantity (density) of shown xticklabels, e.g. to an interval of 5 minutes?

I think the common xticks={5,10,15}-command won’t work because of the inclusion of xticklabels from the data-table (xticklabels from table={Data_Table.csv}{X})…


Thank you very much for your help!

Label positioning in pgfplots

$
0
0

I am using lualatex and I am having trouble positioning the labels of a grouplot at the bottom of the plots. Here is my code

% !Mode:: "TeX:UTF-8"
documentclass[a4paper,12pt]{book} 

usepackage{fontspec}                    
usepackage{polyglossia}                 

usepackage{amsmath,empheq}                     
usepackage{mathtools}                   
usepackage{amscd}                       
usepackage{amsxtra}                     
usepackage{amsthm}                      
usepackage{unicode-math}                

usepackage{tikz}                                     
usepackage{pgfplots}                    
usepgfplotslibrary{groupplots}
pgfplotsset{compat=newest}                

setmainfont{Linux Libertine O}          
setmathfont[bold-style=ISO]{Cambria Math}     

% pgfplotsset style
pgfplotsset{
    gaxisonly axis/.style={
    axis lines=middle,
    axis line style={->}, 
    ticks=none,
    clip=false
    }
}

begin{document}

begin{figure}[htbp]
centering
begin{tikzpicture}[font=footnotesize]
begin{groupplot}[
group style={
group size=4 by 1,
xlabels at=edge bottom,
vertical sep = 1.5cm},
gaxisonly axis,
height=4cm,
width=4cm]
nextgroupplot[xlabel={Function 1}]
addplot[blue,mark=none,domain=-0.5:0.5,samples=100, thick]{abs(x)};
nextgroupplot[xlabel={Function 2}]
addplot[blue,mark=none,domain=-0.5:0,samples=100, thick]{-x};
addplot[blue,mark=none,domain=0:0.5,samples=100, thick]{x^(1/3)};
nextgroupplot[xlabel={Function 3}]
addplot[blue,mark=none,domain=-0.5:0.5,samples=100, thick]{sqrt(abs(x))};
nextgroupplot[xlabel={Function 4}]
addplot[blue,mark=none,domain=-0.5:0.5,samples=100, thick]{x/abs(x)*abs(x)^(1/3)};
addplot[blue,mark=none,domain=-0.5:0,samples=100, thick]{-abs(x)^(1/3)};
end{groupplot}
end{tikzpicture}
caption{Some functions}
end{figure}

end{document}

and here is the result

enter image description here

As you can see the text is above the x axis of the plots instead of the bottom. How can I fix that?

Drawing a square that respects layers pgfplots

$
0
0

I have a pgfplots code that generates a paraboloid on top of a circle;

documentclass[a4paper,10pt]{article}
usepackage[utf8]{inputenc}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
 begin{axis}[view={30}{60}]

 addplot [fill=black, domain=0:2*pi,samples=50]({cos(deg(x))},     {sin(deg(x))});
  addplot3[surf,shader=flat,
 samples=20,
  domain=0:2,y domain=0:2*pi,
  z buffer=sort]
  ({x*cos(deg(y))}, {x*sin(deg(y))}, {x*x});

 end{axis}
end{tikzpicture}
end{document}

It looks like

enter image description here

which is nearly what I’m after. I want to draw a square around the circle in the z=0 plane and be able to fill it (without it covering the circle up) but I cant figure out how to do this.

I tried adding the line

 addplot (-2,2) rectangle (-2,2);

but the rectangle generated is in the wrong plane and also doesnt span the points (-2,-2), (2,2) like I expected.

Mike

Generating minimal-looking graph in pgf plots

$
0
0

I want to generate simple-looking plots such as this one:

Enter image description here

I’ve tried the following:

usepgflibrary{shapes.geometric}
usetikzlibrary{calc}
pgfplotsset{my style/.append style={axis x line=middle, axis y line=
middle, xlabel={$x$}, ylabel={$y$}, axis equal }
begin{document}
    begin{tikzpicture}
    begin{axis}[my style, xticklabels={},extra x ticks ={1} ,yticklabels=none,extra x tick style={xticklabel=pgfmathprintnumber{tick}}]
    addplot[domain=-1:2, red, thick] {x*ln(x)};
    end{axis}
    end{tikzpicture}
end{document}

Is there a way to remove ticks, but keep the tick at ‘x=1′. Also, how can I make this function look smoother?


characteristic of a regression line

$
0
0

I have a little Problem with a regression line I made. I need it to be from its zero up to the x-value of the highest point.

This is how it actually looks und underneath how I need it. Does anyone know how to do this?

Thank you :)

edit: of course, I already tried out domain=x1:x2

enter image description here

enter image description here

documentclass{article}
usepackage{pgfplots}
usepackage{pgfplotstable}

begin{document}
sffamily

pgfplotsset{every axis legend/.append style={
at={(0.03,0.97)},
anchor=north west}}
begin{tikzpicture}
begin{axis}[
    width=10cm,
    height=10cm,
    x tick label style={/pgf/number format/1000 sep=},
    xmin=0, xmax=0.6, ymin=0, ymax=22, 
    xlabel=Weg,/,mm, 
    ylabel=Kraft,/,N,
    ]

pgfplotstableread{data.txt}
datatable


addplot+[
    color = blue,
    fill = blue,
    mark = *,
    mark options={solid},
    only marks,
    ] table {
x       y
0.400   18.096
0.400   18.401
0.400   17.767
0.400   16.992
0.400   16.399
0.397   15.908
0.392   15.440
0.387   14.533
0.382   13.258
0.377   11.939

};
addlegendentry{Kraft-Weg-Kurve}

addplot [
    domain=0.25:0.4
    no markers,
    ] table [
        y={create col/linear regression={y=y}}] {
x       y
0.400   18.096
0.400   18.401
0.400   17.767
0.400   16.992
0.400   16.399
0.397   15.908
0.392   15.440
0.387   14.533
0.382   13.258
0.377   11.939
};
addlegendentry{Regression {$pgfmathprintnumber[precision=4, fixed zerofill]{pgfplotstableregressiona} cdot mathrm{t} + pgfmathprintnumber[precision=4, fixed zerofill]{pgfplotstableregressionb}$}}




end{axis}
end{tikzpicture}


end{document}

Weird axis labelling for large negative values

$
0
0

When using pgfplots to plot certain values, my axis labels “get stuck” at one side of the axis (see the lower right corner of the image below).

The original plot contained many more data points which made it even more ugly.

I have reduced this to these three numbers:

documentclass{article}

usepackage{tikz}
usepackage{pgfplots}
pgfplotsset{compat=1.10}

begin{document}

begin{tikzpicture}
begin{axis}
addplot coordinates { (-323573.5, -327215.79) (-323572.1, -327210.13) (-323572.1, -327206.85) };
end{axis}
end{tikzpicture}

end{document}

enter image description here

How to draw a smooth line through points on a cartesian flammability plot

$
0
0

First attempt to create this plot

enter image description here

The minimum working example:

RequirePackage{filecontents}

begin{filecontents}{CO2.dat}
O2, CO
0, 72
40, 48
46, 39
52, 28
51.5, 22
49.5, 18
40.5, 16
33, 15
26, 15
19, 14.5
8, 14
0, 12.7
end{filecontents}

begin{filecontents}{N2.dat}
O2, CO
0, 72
50, 45
62, 29
65, 25
68, 17
67, 14
66, 13
46, 13
28, 12.8
0, 12.7
end{filecontents}
documentclass[crop,tikz]{standalone}
usepackage{pgfplots,pgfplotstable}

begin{document}

pgfplotstableread[col sep = comma]{N2.dat}Nitrogen 
pgfplotstableread[col sep = comma]{CO2.dat}Carbondioxide 

begin{tikzpicture}
pgfplotsset{compat=newest}
pgfplotsset{width=10cm, height=10cm},

begin{axis}[grid=major,
      xmin=0,xmax=100,
      ymin=0, ymax=80,
ylabel={Carbon Monoxide (mol%)},
xlabel={Oxygen (mol%)},
]
addplot+[] table [x=O2, y=CO, col sep=comma] {Nitrogen}; addlegendentry{Nitrogen};
addplot+[] table [x=O2, y=CO, col sep=comma] {Carbondioxide}; addlegendentry{Carbone dioxide};
end{axis}
end{tikzpicture}

end{document}

Produces this:

enter image description here

How can the curves be drawn as shown in the original figure?

Two sets of labels on pgfplot bar chart

$
0
0

I’d like another set of hard-coded labels that sit on top, near the bottom (0) of each bar. I.e., like the nodes near coords labels, but shifted down towards 0 and with my own custom text. So in the following example, there would be an additional four labels (not shown). Is there an easy way to do that? Thanks!

example

MWE:

documentclass[border=10pt]{standalone}
usepackage{tikz}
usepackage{pgfplotstable}
renewcommand*{familydefault}{sfdefault}
usepackage{sfmath}

pgfplotsset{compat=1.12}
pgfplotsset{
    width=textwidth,
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,axis on top, ymax=100,
ymin=30,
height=8cm,
width=5cm,
enlarge x limits=0.5,
ymajorgrids, tick align=inside,
major grid style={draw=white},
axis x line*=left,
ylabel={%},
xtick=data,
legend cell align=left,
max space between ticks=20pt,
legend style={ at={(0.57,1.05)} ,
                column sep=1ex },
symbolic x coords={label1, label2},
nodes near coords=rotatebox{90}{scriptsizepgfmathprintnumberpgfplotspointmeta},
]
 addplot[draw=none,fill=blue!40!white] coordinates      {(label1,80.2)      (label2,90.7)   }; 
 addplot[draw=none,fill=red!40!white] coordinates      {(label1,70)      (label2,80) }; 

legend{Data1, Data2}
end{axis}
end{tikzpicture}

end{document}

Graphing an arcsin function using pgfplots

$
0
0

I am trying to graph this function using pgfplots:

D(x)=180+2x-4(arcsin(sin(x)/1.33))

What is the how to I represent this in the the addplot function in pgfplots? I am also confused as to what to add in my preamble.

Thanks for the help,
A new member of the community

Viewing all 125 articles
Browse latest View live