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

Specifying which user defined colormap to use in pgfplots

$
0
0

I have figured out how to define my own colormap in pgfplots. My understanding is that when I define my color map and I plot any graph that requires a colorbar, the default coloring scheme used becomes the one that I have defined. My question is, what if I am defining multiple colormaps, how do I specify the one I want to pick? I couldn’t really find the options. Here is a MWE

 documentclass{article}
     usepackage{pgfplots}
     usepackage{tikz}
     pgfplotsset{
        colormap={mygreen}{rgb255(0cm)=(0,0,0); rgb255(1cm)=(0,255,0)}
         }
   begin{document}
      begin{figure}
        begin{tikzpicture}[scale=0.45]
             begin{axis}[view={0}{90},colorbar]
                addplot3[surf, shader=interp] table{
              1      0     2
              2      0     1

              1      1     0
              2      1     3

              1      2     1
              2      2     1
             };
             end{axis} 
         end{tikzpicture}
      end{figure}
   end{document}

The above example will use mygreen colormap. Say for example I have defined another colormap colormap={randcolor}{rgb255(0cm)=(0,100,0); rgb255(1cm)=(100,255,155)}, how would I choose to use that one? At first I used the option colormap/mygreen, but it was giving me some compilation errors.


tikz pgfplots: basic named dots in coordinate system

$
0
0

I know the following is a basic misunderstanding (headscratcher) on my part. I just want to place a few named points into an existing graph. The following is an excerpt:

documentclass{standalone}

usepackage{tikz, pgfplots}
usetikzlibrary{arrows}

%pgfplotsset{compat=1.10}

begin{document}

begin{tikzpicture}
  begin{axis}
    addplot coordinates{(0,0)}; %% as expected
    addplot coordinates{(0,5)}; %% as expected
    addplot coordinates{(1,7)}; %% as expected

    %% all of the below draw at 0,0!
    node[label={T1}] at (0.8,0.8) {T5}; %% puts T1 at 0,0
    draw(0.3,0.3) circle (0.2); %% no effect
    node[label={270:{(0.6,1)}}, circle, fill, inner sep=0.1pt] at (0.6,0.6) {T4};
    node[draw] at (0.8,0.8) {T5};
    draw(0.8,0.8) circle (0.4);
  end{axis}
end{tikzpicture}

end{document}

enter image description here

as always, helps appreciated. this one will probably be a one-liner, but useful for others to look up, too.

/iaw

Drawing a solid angle vector/cone in TikZ?

$
0
0

I would like to draw a “solid angle vector/cone” pointing in a specified direction in spherical coordinates and having a specified opening size (dσ or a in the examples below), akin to the examples below, but only with axes arrows and a vector/arrow for the direction the cone points:

solid angle vector/cone example
solid angle vector/cone example 2

How could I do this in TikZ?

How can I automate the plotting of step functions?

$
0
0

I’m using a lot of step functions in my master’s thesis and would like to automate the plotting. I can get them to look just as I want by hand using this method, but when I try to automate it like this there are two problems (see picture).

  1. The vertical jump is sometimes plotted instead of just being a jump.
  2. The dotted lines to indicate vertical jumps are only drawn the last time I call the command.

How can I fix this?

In the stepfunction command I define the function to be plotted locally in the for-loop. Like this:

  foreach xStart/xEnd  in {minx/s, s/e, e/maxx} {
    addplot[domain=xStart:xEnd, blue, ultra thick,
        declare function={
            pj(x) = and(x >= s, x < e)*(val) + 
                and(x >= e, 1)*(b) + 
                and(1, x < s)*(b);}] 
        {pj(x)};

Is this a good idea? I want to be able to draw many functions in a single picture so I can’t put the whole axis environment in the newcommand, right?

Left: automated plot, right: plot by hand.

Code

documentclass[border=3pt]{standalone}

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


pgfkeys{
  stepfunction/.is family,
  stepfunction,
  plotstart/.initial=0,
  plotend/.initial=5,
  start/.initial=1,
  end/.initial=2,
  value/.initial=1,
  base/.initial=0
}
newcommandstepfunctionset[1]{pgfkeys{stepfunction,#1}}
newcommandstepfunction[1][]{
  stepfunctionset{#1,
    plotstart/.get=minx,
    plotend/.get=maxx,
    start/.get=s,
    end/.get=e,
    value/.get=val,
    base/.get=b
  }
  % plot from minx to maxx
  foreach xStart/xEnd  in {minx/s, s/e, e/maxx} {
    addplot[domain=xStart:xEnd, blue, ultra thick,
        declare function={
            pj(x) = and(x >= s, x < e)*(val) + 
                and(x >= e, 1)*(b) + 
                and(1, x < s)*(b);}] 
        {pj(x)};
  };
  draw[dotted] (axis cs:s,b) -- (axis cs:s,val);
  draw[dotted] (axis cs:e,b) -- (axis cs:e,val);
  addplot[color=blue,fill=white,only marks,mark=*] 
    coordinates{(s,b)(e,val)};
  addplot[color=blue,only marks,mark=*] 
    coordinates{(s,val)(e,b)};
}

begin{document}
begin{tikzpicture}[scale=1.5, thick]
  begin{axis}[xmin=-1, xmax=6, ymax=3.5]
    % p_{j-1,1}
    stepfunction[plotstart=-1, plotend=2.5, 
        start=0, end=2, value=1, base=0]
    % p_{j+1,6}
    stepfunction[plotstart=2.5, plotend=3.75, 
        start=3, end=3.5, value=3, base=0]
    % p_{j,4}
    stepfunction[plotstart=3.75, plotend=6, start=4, end=5, value=2]
  end{axis}
end{tikzpicture}

% Plot by hand
begin{tikzpicture}[
  scale=1.5,
  thick,
  soldot/.style={color=blue,only marks,mark=*},
  holdot/.style={color=blue,fill=white,only marks,mark=*},
  declare function={
    pj(x)=and(x >= 0, x < 1)*(1) + 
        and(x >= 1, 1)*(0) + 
        and(1, x < 0)*(0);
    }]
  begin{axis}[xmin=-1, xmax=6, ymax=3.5]

    % p_{j-1,1}
    foreach xStart/xEnd  in {-1/0, 0/2, 2/3} {
        addplot[domain=xStart:xEnd, blue, ultra thick] {pj(0.5*x)};
    }
    draw[dotted] (axis cs:0,0) -- (axis cs:0,1);
    draw[dotted] (axis cs:2,0) -- (axis cs:2,1);
    addplot[holdot] coordinates{(0,0)(2,1)};
    addplot[soldot] coordinates{(0,1)(2,0)};


    % p_{j+1,6}
    foreach xStart/xEnd  in {3/3.5, 3.5/4} {
        addplot[domain=xStart:xEnd, blue, ultra thick]
            {pj(2*(x-3))*3};
    }
    draw[dotted] (axis cs:3,0) -- (axis cs:3,3);
    draw[dotted] (axis cs:3.5,0) -- (axis cs:3.5,3);
    addplot[holdot] coordinates{(3,0)(3.5,3)};
    addplot[soldot] coordinates{(3,3)(3.5,0)};

    % p_{j,4}
    foreach xStart/xEnd  in {4/5, 5/6} {
        addplot[domain=xStart:xEnd, blue, ultra thick] 
            {pj((x-4))*2};
    }
    draw[dotted] (axis cs:4,0) -- (axis cs:4,2);
    draw[dotted] (axis cs:5,0) -- (axis cs:5,2);
    addplot[holdot] coordinates{(4,0)(5,2)};
    addplot[soldot] coordinates{(4,2)(5,0)};

  end{axis}
end{tikzpicture}

end{document}

Edit

Using the option jump mark left for plotting solves the first problem and makes the foor-loop unnecessary:

% plot from minx to maxx
addplot[domain=minx:maxx, blue, ultra thick, jump mark left,
        declare function={
            pj(x) = and(x >= s, x < e)*(val) + 
                and(x >= e, 1)*(b) + 
                and(1, x < s)*(b);}] 
        {pj(x)};

Thanks Paul Stiverson!

pgfplots external with large dataset (lualatex?)

$
0
0

I have fairly large datasets with densely strucutred data that i cant downsampe much without loosing structure. I use TexMaker on Ubuntu 14.04LTS. I use

usepackage{tikz,pgfplots,pgfplotstable}
pgfplotsset{compat=1.9}
usepgfplotslibrary{external}
tikzexternalize

and

tikzsetnextfilename{figs/test1}

to externalize the figures. This works good compiling with pdflatex -shell-escape. But as the data becomes to large I am out of memory. I am trying to compile using LuaLaTeX -shell-escape instead of pdfLatex but get the following error message:

! Package tikz Error: Sorry, the system call 'pdflatex -halt-on-error -interact
ion=batchmode -jobname "figs/test1" "deftikzexternalrealjob{article}input{ar
ticle}"' did NOT result in a usable output file 'figs/test1' (expected one of .
pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pd
flatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18'
or something like that. Or maybe the command simply failed?

so pgfPlots seem to call pdfLatex without the appropriate -shell-escape flag and without me specifying it. How can i get this to compile in LuaLatex? or can i compile only the figures in LuaLatex and the rest in pdfLatex (the opposite of what is happening now)? I found this and this example but neither helped me…

Thankfull for help and i am also thankful for any general advice that can help me resolve the problem of ploting larger data sets in pgfplots.

Cheers /J

Some modifications to the axis environment

$
0
0

I have the graph of a function and its inverse. I would like two slight modifications to the axis environment.

I want grid lines drawn at multiples of 5 from the axes. For some reason, the vertical grid lines are drawn at multiples of 2 from the y-axis. (I also don’t want the tick marks labeled on the axes because I am not specifying the functions on the graphs.) I have xmin=-12,xmax=17,ymin=-12,ymax=17,, but the axes are drawn far past these bounds. It looks awkward.

documentclass{amsart}
usepackage{tikz}
usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
usepackage{pgfplots}
pgfplotsset{compat=1.11}

begin{document}

begin{tikzpicture}
begin{axis}[width=textwidth,grid=both,grid style={line width=.1pt, draw=gray!10},clip=false,
    xmin=-12,xmax=17,ymin=-12,ymax=17,
    axis lines=middle,
    restrict x to domain=-12:17,restrict y to domain=-12:17,
    enlargelimits,
    axis line style={shorten >=-0.1cm,shorten <=-0.1cm,latex-latex},
    %xtick={empty},ytick={empty},
    ticklabel style={fill=white},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]

addplot[dashed,line width=0.2pt,domain=-10:16,latex-latex,name path=reflection_line] {x} node[fill=white, above, right]{$y=x$};
addplot[domain=-10:16,draw=none,name path=perpendicular_line] {-x + 15};
addplot[green,domain=-10:4,samples=101,name path=an_exponential_function]  {pow(2,x)} node[fill=white, above, right]{$y=f(x)$};
addplot[blue,domain=1/2^10:16,samples=101,name path=a_logarithm_function]  {log2(x)} node[fill=white, below=5pt] {$y=f^{-1}(x)$};

%The intersection of reflection_line and perpendicular_line is (5,5). The following commands
%label the point R and mark it with a point.
coordinate (R) at (7.5,7.5);
addplot[mark=*,mark size=1.5pt] coordinates {(7.5,7.5)};

coordinate[name intersections={of=perpendicular_line and an_exponential_function,by={P}}];
draw[fill,green] (P) circle (1.5pt);
coordinate[name intersections={of=perpendicular_line and a_logarithm_function,by={Q}}];
draw[fill,blue] (Q) circle (1.5pt);

%These commands put a brace above line segment PR and label the length `d`.
%First, coordinates for P' and R' are defined to be 2.5pt from PR. A brace is drawn between P'
%and R'. In this way, the label for the length of PR is put in the center of the brace by
%default.
coordinate (P') at ($(P)!2.5pt!90:(R)$);
coordinate (R') at ($(R)!2.5pt!-90:(P)$);
draw[decorate,decoration={brace,amplitude=5pt}] (P') -- node[above right=3.5pt and 3.5pt,fill=white, inner sep=1pt]{$scriptstyle{d}$} (R');

%These commands put a brace above line segment QR and label the length `d`.
%First, coordinates for Q' are defined to be 2.5pt from QR. A brace is drawn between Q'
%and R'. In this way, the label for the length of QR is put in the center of the brace by
%default.
coordinate (Q') at ($(Q)!2.5pt!-90:(R)$);
draw[decorate,decoration={brace,mirror,amplitude=5pt}] (Q') -- node[above right=3.5pt and 3.5pt,fill=white, inner sep=1pt]{$scriptstyle{d}$} (R');
end{axis}
end{tikzpicture}

end{document}

Auto label points read from file

$
0
0

My question is the following, I read data from txt file where the data are stored as:

North,East 
1,5
4,7

a file with code

pgfplotstableread[col sep=comma, header=true {data.csv}table;
addplot [color=black, mark=*, only marks] table[x=East, y=North] from table;

It’s possibile to enumerate the point plot in order that 1,2,3,… as the row of txt file

3d Graph Error with Plot

$
0
0

I have a problem with plotting a 3d-graph

begin{tikzpicture}
  begin{axis}[
     title=Exmple using the mesh parameter,
     hide axis,
     colormap/cool,
  ]
  addplot3[
     mesh,
     samples = 40,
     domain=0:1,
    ]
    {exp(-(ln(x)-ln(y))};
  addlegendentry{$frac{sin(r)}{r}$}
  end{axis}
end{tikzpicture}

The problem is

Package pdfplots Error: An internal error occurred during z buffer reordering: the rows/cols where not balanced! I have rows=40, cols=40. If this happens to be wrong, you might want to provide rows and cols manually…

Is there anyone who knows how to fix the problem? It works e.g. with the function sin(x)*sin(y)…


Can I increase the accuracy of pgfplots?

$
0
0

Working on a pgfplots solution to this question, I faced the following problem. When I plot only one branch of a square root function, the plot seems to be OK; but when I add the minus part of the function, the plot seems to be shifted up at the value x=0.0.

%pdfLaTeX
documentclass{standalone}
usepackage{pgfplots}

begin{document}
begin{tikzpicture}

begin{axis}[axis lines = center,samples=100]
    addplot [] {+sqrt(x)};
    addplot [] {-sqrt(x)};
end{axis}

end{tikzpicture}
end{document}

This is what is gained by plotting only addplot [] {+sqrt(x)};

enter image description here

This is what I have when I plot both functions;

enter image description here

Also, when I add to the amount of plotting samples, the problems seems to get be solved but it is highly dependent on the value of the samples and the problem is not solved completely.

This is what I have for samples=500

enter image description here

Why this happens? Is this because I need to define some accuracy in plotting functions? Why does not this happen when I only plot one function?

How can we define a custom variant of addplot, including new keys and default values?

$
0
0

I frequently create plots with addplot using a lot of optional arguments, making it difficult to keep the code consistent. I have a few repeating plotstyles so I tried to implement a new macro that can be used like:

newaddplot[style=mystyle1,draw=red]{mydatafile.txt};

I want to retain the structure and keys of the original addplot function and also add new keys. My approach below uses pgfkeys to parse the key-value pairs of newaddplot, handle my new keys and pass the rest to the addplot command inside newaddplot. The MWE uses “draw” and “offset” as an example of an existing and a new key.

documentclass{standalone} 
usepackage[english]{babel}
usepackage{pgfplots,pgfkeys}pgfplotsset{compat=newest}

begin{document}%

newcommandoffset{0}        
pgfkeys{
/newaddplot/.is family, /newaddplot,
default/.style = {offset=0},
offset/.code = {renewcommandoffset{#1}},
.unknown/.code={
letcurrnamepgfkeyscurrentname
letcurrvalpgfkeyscurrentvalue
ifx#1pgfkeysnovalue
pgfqkeys{/pgfplots}{remainingkeys/.append style/.expand once={currname}}
else
pgfqkeys{/pgfplots}{remainingkeys/.append style/.expand twice={expandaftercurrnameexpandafter=currval}}
fi
}}    

newcommandnewaddplot[1][]{
pgfqkeys{/pgfplots}{remainingkeys/.style={}}% reset remainingkeys
% pgfplotsextra{ %uncomment here ...
pgfkeys{/newaddplot,default,#1}%set default values and parse key-value pairs
% } % ... and here fixes colors but ignores offset
addplot[/pgfplots/remainingkeys] coordinates {(0,0+offset)(1,1+offset)} % use parsed keys for plot
}

begin{tikzpicture}     
    begin{axis}    
        newaddplot[draw=red,ultra thick,offset=1];
        newaddplot[draw=blue,dashed];
    end{axis}
end{tikzpicture}  

end{document}

The problem is that the attributes of the last newaddplot are used for all plots (here draw=blue,dashed). After some research i found that this is because “any drawing commands inside of an axis need to be postponed until the axis is complete” (pgfplotsmanual Chapter 8.3). Using pgfplotsextra (uncommenting the two lines in the MWE) uses ALL attributes specified before, i.e. the “ultra thick” from the first plot is also applied to the second plot. In Addition the offset is not working anymore.
output with and without pgfplotsextra

How can I make sure that the keys only affect the corresponding plot?

Latex bar graph PGFPlots

$
0
0

Im trying to create a bar plot but something doesn’t go quite right the bar plot is sort of scrambled and i can figure out where it goes wrong .

Here is what is have

    documentclass[border=10pt]{standalone}
%%%<
usepackage{verbatim}
%%%>
usepackage{pgfplots}
pgfplotsset{width=30cm,compat=1.8}

begin{document}
begin{tikzpicture}
begin{axis}[
    x tick label style={},
    ylabel=Population,
    enlargelimits=0.05,
    legend style={at={(0.5,-0.15)},
        anchor=north,legend columns=-1},
    ybar interval=0.1,
     symbolic x coords={Technical quality,WOZ / Company Value,AH / MH,rooms,Surface,Rentability indicator,EPA,Neighborhood,WW,WOZ / area,EPA label,Market risk,Company Value / remant life,WWS,Surface,Popularity,BW / MW ratio,Rent class,WW,Target Rent,Year Built,Techical quality,rooms,Mark rent,Remant life,Max reas rent,Target rent,Mark rent,Net rent,Max reas rent,Net rent},
        x tick label style={rotate=45,anchor=east},
        xtick=data,
]
addplot coordinates {(Technical quality,0.078)(WOZ / Company Value,0.072)(AH / MH,0.069)(rooms,0.064)(Surface,0.062)(Rentability indicator,0.052)(EPA,0.051)(Neighborhood,0.047)(WW,0.045)(WOZ / area,0.036)(EPA label,0.035)(Market risk,0.034)(Company Value / remant life,0.033)(WWS,0.029)(Surface,0.029)(Popularity,0.028)(BW / MW ratio,0.028)(Rent class,0.027)(WW,0.026)(Target Rent,0.023)(Year Built,0.022)(Techical quality,0.02)(rooms,0.02)(Mark rent,0.014)(Remant life,0.012)(Max reas rent,0.012)(Target rent,0.009)(Mark rent,0.008)(Net rent,0.008)(Max reas rent,0.004)(Net rent,0.004)} ;

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

Fermi–Dirac in pgfplots, dimension too lage

$
0
0

I’m trying to draw a plot of the Fermi-Dirac distribution,

enter image description here

for which I’d like to show a few lines of varied temperate (T). My code works for this, except for zero temperature, it results in a Dimension too large error from pgfplots. Is there a way to resolve this while keeping the real value of the Boltzman constant, k_B, in electron volts?

MWE:

documentclass[tikz,border=5pt]{standalone}
usepackage{pgfplots}

pgfplotsset{compat=newest}

begin{document}

begin{tikzpicture}
begin{axis}[
    xlabel=$frac{mv^2}{2k_BT}$ (eV),
    ylabel=$f(n)$,
    legend entries={0 K,100 K,1000 K,10000 K},
    x tick style={color=black},
    y tick style={color=black},
    xtick pos=left,
    ytick pos=left,
    xmin=-3,
    xmax=3,
    ymin=-0.1,
    ymax=1.1
    ]
addplot[samples=50,black] {(1/((exp((x)/(80.617e-5))+1))};
addplot[samples=50,blue,dashed] {(1/((exp((x)/(8.617e-3))+1))};
addplot[samples=50,red,dashed] {(1/((exp((x)/(8.617e-2))+1))};
addplot[samples=50,green,dashed] {(1/((exp((x)/(8.617e-1))+1))};
end{axis}
end{tikzpicture}

end{document}

This code compiles but 80.617e-5 should be 8.617e-5 which breaks the code. I’ve tried varying/removing xmin, xmax with no success. I also read in a few answers something to do with fpu but this didn’t seem to work for me or is no longer required? restrict x to domain did not seem to help, though I could be using it wrong.

enter image description here

Can you use `pgfplotstable` to do a linear regression to an expression?

$
0
0

I have a lot of data in a table, but it is not linearly related. I can linearize the relationship by computing functions (x expr and y expr expressions). I would like to use pgfplots to show the results of the data expressions in a pgfplot and use the create col/linear regression operation to find and plot the regression line.

Here is a MWE

documentclass{article}
usepackage{tikz}
usepackage{pgfplots,pgfplotstable}
usepackage{siunitx}
begin{document}
    pgfplotstableread{%
     myx myy
     1 1
     2 1.41
     3 1.67
     4 2.03
     5 2.2
     6 2.45
     9 2.97
}mytable

    begin{tikzpicture}
    begin{axis}[xlabel=my x,ylabel=(my y)$^2$]
    addplot[only marks] table {mytable}; %
    addplot[only marks] table[y expr=thisrow{myy}*thisrow{myy}] {mytable};    
    addplot[no marks] table[y={create col/linear regression={y=myy}}] {mytable}; %

%    addplot[no marks] table[y={create col/linear regression={y expr={thisrow{myy}*thisrow{myy}}}}] {mytable};
    end{axis}
    end{tikzpicture}
end{document}

Here’s the output:
enter image description here

I have plotted both myx vs myy and myx vs myy$^2$ data points, and the linear regression of the raw data. When I try to do a linear regression on the square of myy I get errors. The specific errors depend on the form of the [y={create col/linear regression={....}}] statement that I try, and I have tried many which don’t work.

Is it possible to do this regression in the pgfplots/pgfplotstable context? If not, short of inputting the linearized data points, what will do it, because I already have the data table in LaTeX …

(And WHY doesn’t this SE section support MathJax input?!)

Showing legend for boxplot in pgfplots

$
0
0

I am trying to display a legend for a boxplot created in pgfplots.

However the size of the legend is almost as large as the plot and covers up all of my plot, how do I fix this?

enter image description here

documentclass{standalone}
usepackage{pgfplots}
usetikzlibrary{pgfplots.statistics}
pgfplotsset{compat=1.12}
begin{document}
begin{tikzpicture}

begin{axis}[
  legend entries = {A, B},
]

addplot+[boxplot] table [row sep=\, y index=0] {
  data\ 9\ 6\ 7\ 7\ 3\ 9\ 10\ 1\ 8\ 7\ 9\ 9\ 8\ 10\ 5\ 10\     10\ 9\ 10\ 8\
};

addplot+[boxplot] table [row sep=\, y index=0] {
  data\ 9\ 6\ 7\ 7\ 3\ 9\ 10\ 1\ 8\ 7\ 9\ 9\ 8\ 10\ 5\    10\ 10\ 9\ 10\ 8\
};

end{axis}

end{tikzpicture}
end{document}

If one removes either the words legend entries = {A, B} or boxplot from the code, the graphs are displayed as expected, just without a legend respectively not as a boxplot.

I suspect this to be a bug in pgfplots, are there any workarounds?

Specifications in the axis environment ignored

$
0
0

This is a similar display from another post of mine. There are only two differences. (One of these differences is the placements of the labels for the lines. In my post, I had the labels along the lines. Due to the comments from Gonzalo Medina, I now have the labels at the end of the lines.) The other difference is that I edited the axis environment to make it more concise. I added

x tick label style={font=tiny,fill=white,anchor=south,shift=-4pt}

to xticklabel style= and

y tick label style={font=tiny,fill=white,anchor=west,shift=-4pt}

to yticklabel style=. Why are these specifications are ignored?

documentclass{amsart}
usepackage{amsmath}

usepackage{tikz}
usetikzlibrary{calc,angles,positioning,intersections}


usepackage{pgfplots}
pgfplotsset{compat=1.11}


begin{document}

begin{tikzpicture}
begin{axis}[width=5in,axis equal image,clip=false,
    xmin=-54,xmax=90,ymin=-54,ymax=90,
    restrict y to domain=-54:90,
    enlargelimits={abs=0.5cm},
    xtick={empty},ytick={empty},
    extra x ticks={15},
    extra x tick labels={15},
    xticklabel style={x tick label style={font=tiny,fill=white,anchor=south,shift=-4pt}},
    extra y ticks={15},
    extra y tick labels={15},
    yticklabel style={y tick label style={font=tiny,fill=white,anchor=west,shift=-4pt}},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]

%These commands draw the line y=x and put the label "$ell$" 7.5pt from the right arrow tip
%in the same direction of the line.
addplot[dashed,latex-,samples=2,domain=-54:-21,blue]{(1/3) * x + 36};
addplot[dashed,-latex,samples=2,domain=18:90,blue]{(1/3) * x + 36};
addplot[dashed,latex-latex,samples=2,domain=-54:90]{x};
node at ($(axis cs:90,90)!7.5pt!(axis cs:100,100)$) {$ell$};

%These commands label the vertices of triangle ABC. P is the point on line segment AC at the
%base of the altitude from B.
draw (axis cs:-30,-30) coordinate(A) node[left]{$A$};
draw (axis cs:-21,29) coordinate(B) node[above left]{$B$};
draw (axis cs:18,42) coordinate(C) node[above]{$C$};
draw (axis cs:0,15) coordinate(P);

%These commands draw a line through B and C.
addplot[dashed,latex-,samples=2,domain=-54:90,blue]{(1/3) * x + 36};

%These commands label the vertices of triangle AB'C'. (The reflection of B across the line
%y=x is labeled B' and the reflection of C across the line y=x is labeled C'.) P' is the
%point on line segment AC' at the base of the altitude from B'.
draw (axis cs:29,-21) coordinate(B') node[below right]{$B^{prime}$};
draw (axis cs:42,18) coordinate(C') node[right]{$C^{prime}$};
draw (axis cs:15,0) coordinate(P');

%These commands draw a line through B' and C'. (Its domain is expressed as the union of the
%intervals [18,29] and [42,66] because the side B'C' is dashed and the line through B' and
%C' is drawn with "loosely dash dot.")
addplot[latex-,samples=2,loosely dash dot,domain=18:29,green]{3 * x - 108};
addplot[-latex,samples=2,loosely dash dot,domain=42:66,green]{3 * x - 108};

draw [fill] (54,54) circle [radius=1.5pt];
end{axis}

draw[blue] (A) -- (B) -- (C) -- cycle;
draw[dashed,blue] (B) -- (P);


draw[dashed,green] (A) -- (B') -- (C') -- cycle;
draw[densely dashed,green] (B') -- (P');

end{tikzpicture}

end{document}

Draw axis line on top macro does not work with colorbar

$
0
0

I have a macro from here: Force "axis on top" for plotmarks in pgfplots

Which allows me to draw the axis line on top of the markers. However, if I use it in conjunction with a colorbar, it does not work correctly, as the ticks and ticklabels for the colorbar are transparent

makeatletter newcommand{pgfplotsdrawaxis}{pgfplots@draw@axis} makeatother

pgfplotsset{axis line on top/.style={
  axis line style=transparent,
  ticklabel style=transparent,
  tick style=transparent,
  axis on top=false,
  after end axis/.append code={
    pgfplotsset{axis line style=opaque,
      ticklabel style=opaque,
      tick style=opaque,
      grid=none,
      every extra x tick/.style={grid=none},
      every extra y tick/.style={grid=none}}
    pgfplotsdrawaxis}
  }
}

Here a MWE:

documentclass{article}

usepackage{pgfplots}
usepackage{pgfplotstable}

pgfplotsset{compat=1.12}

    pgfplotsset{axis line on top/.style={
      axis line style=transparent,
      ticklabel style=transparent,
      tick style=transparent,
      axis on top=false,
      after end axis/.append code={
        pgfplotsset{axis line style=opaque,
          ticklabel style=opaque,
          tick style=opaque,
          grid=none,
          every extra x tick/.style={grid=none},
          every extra y tick/.style={grid=none}}
        pgfplotsdrawaxis}
      }
    }

begin{document}

pgfplotstableread{
A B C
0 5 -1
0.5 2 0
1 7 1
1.5 11 1.5
}mytable %


begin{tikzpicture}

pgfplotsset
{
colormap
={test}{color=(green); color=( green!75!black);color=(black)}
}

    makeatletter newcommand{pgfplotsdrawaxis}{pgfplots@draw@axis} makeatother

begin{axis}[
axis line on top,
xmin=0,
colorbar,
]
        addplot[%
            scatter,%
            only marks,
            mark=*,
            scatter src=explicit,
            colormap name=test,
            ] table [x={A}, y ={B},meta ={C}] %
            {mytable};
end{axis}
end{tikzpicture}

end{document}

Change ONLY the color of the plot for z = 0 with surf, possible?

$
0
0

Is it possible to change the classical blue color for the surface on the plane at z = 0? I would like to change ONLY the blue with a transparent colour or white.
Thanks.

Boxed equation in pgfplots

$
0
0

I’d like to put an equation within a box. This equation is a label for a picture I’m making by means of pgfplots, tikzpicture environment.
Here is the code

documentclass{standalone}
usepackage{pgfplots}

pgfplotsset{compat=1.12}
usepgfplotslibrary{fillbetween}

begin{document}
begin{tikzpicture}[scale = 1.0]
begin{loglogaxis}
    [
    title = Test,
    xlabel = {$k_{perp}$},
    ylabel = {$k_{parallel}$},
    xmin = 1, xmax = 1e3,
    ymin = 1, ymax = 1e3,
    legend style = {draw = none, font = small}, legend pos = north west, %DRAW is box
    ]

addplot[black, very thick, dashed, domain = 1e0:1e3, samples = 100]{x};
node at(axis cs: 2e2,4e2) {tiny textcolor{black}{$k_{parallel} = k_{perp}$}};

end{loglogaxis}
end{tikzpicture}
end{document}

The equation I wanna put in a box is the one in the node command.
I’ve found a way to create a box but I can’t use it inside the node command.

usepackage{empheq}
newenvironment{boxedeq*}
  {empheq[box=fbox]{equation*}}
  {endempheq}

begin{document}
begin{boxedeq*}
k_{parallel} = k_{perp}
end{boxedeq*}
end{document}

Any working solution is fine, how can I do this?

Thanks

pgfplot, placing 3 graphs next to each other in one coordinate system with different headers

$
0
0

I want to create this graph:

enter image description here

The graph is from a scientific paper which I want to quote in my master thesis. As it looks nicer if I create the graph myself than inserting it as a picture, I need your help

I don’t know how to separate the graphs like in the picture and give them different headers.

usepackage{pgfplots}


begin{figure}[H]
centering
begin{tikzpicture}
begin{axis}[
ybar,
width=textwidth,
bar width=6mm,
ylabel={Conservation impact (%)},
symbolic x coords={Newfoundland Power, Hydro One TOU 1, Hydro One RTM, BC Hydro, Woodstock Hydro, SRP, Country Energy, Hydro One TOU 2},
xtick =data,
x tick label style={rotate=90,anchor=east},
]
addplot coordinates {(Newfoundland Power, 18) (Hydro One TOU 1, 6.8)(Hydro One RTM, 6.4)(BC Hydro, 2.8)(Woodstock Hydro, 15)(SRP, 12.9)(Country Energy, 8)(Hydro One TOU 2, 6.8)};
end{axis}
end{tikzpicture}
end{figure}

Placing pgfplot graphs side-by-side in two column format

$
0
0

I am trying to put three graphs side by side in two column format. The figures is shown below.

My LaTeX code is as following:

   begin{figure*}
   centering
   %includegraphics[height=4.5in]{state3}
   label{fig:graph1}
   begin{tikzpicture}[yscale=0.7, xscale=0.7]
   begin{axis}[
   xmax=100,xmin=0,
   ymin= 0,ymax=1,
   xlabel=emph{User Requests},ylabel=emph{$E_{res}$ Percent},
   xtick={0,10,20,...,100},
   ytick={0,0.1,0.2,...,1},
   legend style={legend pos=north east}
   ]

   addplot coordinates{(0,1.0) (10,0.96) (20,0.90) (30,0.85) (40,0.81)          
   (50,0.74) (60,0.70) (70,0.64) (80,0.59) (90,0.53) (100,0.47)};
   addplot coordinates{(0,1.0) (10,0.93) (20,0.85) (30,0.78) (40,0.71)    
    (50,0.65) (60,0.57) (70,0.50) (80,0.43) (90,0.36) (100,0.29)};
    addplot coordinates{(0,1.0) (10,0.92) (20,0.82) (30,0.70) (40,0.62)  
    (50,0.53) (60,0.43) (70,0.35) (80,0.26) (90,0.18) (100,0.11)};
    legend{emph{10 Nodes},emph{8 Nodes},emph{6 Nodes}}
    end{axis}
    end{tikzpicture}
     %caption{$E_{res}$ vs Total User Requests for Requests Demanding 2-4  
     $vCPU$, 0-2 GB $Memory$}
     %centering
     %includegraphics[height=4.5in]{state3}
    label{fig:graph2}
    begin{tikzpicture}[yscale=0.7, xscale=0.7]
    begin{axis}[
    xmax=100,xmin=0, 
    ymin= 0,ymax=1,
    xlabel=emph{User Requests},ylabel=emph{$E_{res}$ Percent},
    xtick={0,10,20,...,100},
    ytick={0,0.1,0.2,...,1},
    legend style={legend pos=north east}
    ]

    addplot coordinates{(0,1.0) (10,0.94) (20,0.88) (30,0.82) (40,0.75)  
    (50,0.68) (60,0.62) (70,0.55) (80,0.49) (90,0.42) (100,0.34)};
    addplot coordinates{(0,1.0) (10,0.92) (20,0.83) (30,0.74) (40,0.67)         
    (50,0.58) (60,0.50) (70,0.43) (80,0.35) (90,0.27) (100,0.19)};
    addplot coordinates{(0,1.0) (10,0.90) (20,0.81) (30,0.70) (40,0.60)  
    (50,0.51) (60,0.42) (70,0.32) (80,0.23) (90,0.11) (100,0.04)};
    legend{emph{10 Nodes},emph{8 Nodes},emph{6 Nodes}}
    end{axis}
    end{tikzpicture}
    %caption{$E_{res}$ vs Total User Requests for Requests Demanding 3-5  
    $vCPU$, 2-4 GB $Memory$}

     %centering  
     %includegraphics[height=4.5in]{state3}
     label{fig:graph3}
     begin{tikzpicture}[yscale=0.7, xscale=0.7] 
     begin{axis}[
     xmax=100,xmin=0,
     ymin= 0,ymax=1,
     xlabel=emph{User Requests},ylabel=emph{$E_{res}$ Percent},
     xtick={0,10,20,...,100},
     ytick={0,0.1,0.2,...,1},
     legend style={legend pos=north east}
     ]

     addplot coordinates{(0,1.0) (10,0.93) (20,0.86) (30,0.81) (40,0.77)  
     (50,0.69) (60,0.60) (70,0.53) (80,0.45) (90,0.38) (100,0.32)};
     addplot coordinates{(0,1.0) (10,0.91) (20,0.84) (30,0.77) (40,0.70) 
     (50,0.63) (60,0.53) (70,0.44) (80,0.35) (90,0.26) (100,0.18)};
     addplot coordinates{(0,1.0) (10,0.89) (20,0.80) (30,0.72) (40,0.63) 
     (50,0.53) (60,0.46) (70,0.37) (80,0.28) (90,0.18) (100,0.11)};
     legend{emph{10 Nodes},emph{8 Nodes},emph{6 Nodes}}
     end{axis} 
     end{tikzpicture}
     %caption{$E_{res}$ Percent vs Total User Requests for Requests   
     Demanding 2-4 $vCPU$, 2-4 GB $Memory$}
     end{figure*}

enter image description here

My problem:
The graphs are not set in a single row.

Viewing all 125 articles
Browse latest View live