I am plotting data with pgfplots using semilogxaxis that use base 10 logarithm.  Is there a way to change the base of logarithmic-axes (I need an axis where power of 2 values are separated by the same amount of pixels) ?
124193
I have made a chart using pgfplots as written below and I want to have the y-axis in logarithmic scale. This code works fine but the base of the logarithm is 10. How can I change it to base 2?  \begin{tikzpicture}     \begin{axis}[         height=0.5\textwidth,         width=\textwidth,         xlabel=LabelX,         xtick={1,...,10},         ylabel=LabelY,         ymode=log,     ]         \addplot[mark=*,blue] table[x=V,y=R] {data1.data};         \addplot[mark=x,red] table[x=V,y=E] {data2.data};     \end{axis} \end{tikzpicture}
21350
When I found that a simple x^(1.0/3.0) does not yield a graph in PGFplots for negative values of x, I attempted to define my own function for CubeRoot using pgfmathdeclarefunction as below. But, am not able to get them to work.    These are based on , and .   This compiles as is, but has a problem if I set \DomainMin to a negative value. The CubeRootB function does not even compile, and I do not see what the problem with it is.  \documentclass{article} \usepackage{tikz}  \newcommand*{\DomainMin}{0.1} %\newcommand*{\DomainMin}{-2.0} % CubeRootA gives and error if DomainMin &lt; 0  \tikzstyle{MyPlotStyle}=[domain=\DomainMin:2,samples=100,smooth]  \pgfmathdeclarefunction{gauss}{3}{% From links mentioned in the question     \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}% }  \pgfmathdeclarefunction{CubeRootA}{1}{%     \pgfmathparse{%         ifthenelse(equal(#1,abs(#1)),%             (#1)^(1.0/3.0),%            #1 &gt;= 0             -1.0*((abs(#1))^(1.0/3.0))% #1 is negative         )%     }% }  \pgfmathdeclarefunction{CubeRootB}{1}{%     \pgfmathparse{%         \pgfmathifthenelse             {\pgfmathequal{#1}{\pgfmathabs{#1}}}%             {exp(ln(#1)/3.0)}%            #1 &gt;= 0             {-1.0*(exp(ln(abs(#1))/3.0))}% #1 is negative     }%      }  % Modified version of CubeRootB per Caramdir's suggestion \pgfmathdeclarefunction{CubeRootC}{1}{%         \pgfmathparse{%             ifthenelse(                 equal(#1,abs(#1)),%                 exp(ln(#1)/3.0),%            #1 &gt;= 0                 -1.0*(exp(ln(abs(#1))/3.0))% #1 is negative             )         }%     }      \begin{document} \begin{tikzpicture} \draw [help lines] (-2,-2) grid [step=0.5] (2,2); \draw plot [MyPlotStyle] (\x,{gauss(\x,0,0.5)}); % \draw plot [MyPlotStyle] (\x,{    CubeRootA(\x)});% Error if DomainMin &lt; 0 %\draw plot [MyPlotStyle] (\x,{1.0+CubeRootB(\x)});% Does not compile \draw plot [MyPlotStyle] (\x,{    CubeRootC(\x)});% Error if DomainMin &lt; 0 \end{tikzpicture} \end{document}
61145
I am trying to customize the legend for this graph. First of all, I would like the legend width to be equal to the x-axis width. At the moment, I am setting the width of the legend via      /tikz/every even column/.append style={column sep=1.0cm}   and I could manually adjust this value so that length equals the x-axis width, but I guess that there is a more elegant way to set the width of the legend.  Second, I don't really like the little color rectangles in the legend. I only want one rectangle in front of every entry and not two. This rectangle does not need to have a border and should be vertically centred with the text. The alignment seems to be okay for the rectangle closer to the text, but not for one the far left.   Update: Thanks to Christian Feuersänger's comment, there is possibility to change the rectangles via   legend image code/.code={%     \draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);   or what Gonzalo Medina proposed  legend image code/.code={%     \draw[#1, draw=none, /tikz/.cd, bar width=3pt, yshift=-0.2em, bar shift=0pt] %     plot coordinates {(2*\pgfplotbarwidth,0.6em)};   Third, I would like to the legend entries to start next to the text "Legend:".  I don't really know if with these requirements it still makes sense to use legend or if it would be better to add everything manually via after end axis/.code and \ref{label}.  Graph    MWE  \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=newest}  \begin{document} \begin{tikzpicture}     \begin{axis}[                 ybar,                 height=6cm,                 title={Some plot},                 width=12cm,                 axis on top,                 y axis line style={opacity=0},                 axis x line*=bottom,                 tick align=inside,                 tick style={draw=none},                 xtick=data,                 ymajorgrids,                 major grid style={draw=white},                 xtick={1,2,3,4},                 legend style={                     at={(0.0,-0.15)},                     anchor=north west,                     legend columns=-1,                     /tikz/every even column/.append style={column sep=1.0cm}                         },             ]                    \addlegendimage{empty legend}             \addlegendentry{\textbf{Legend:}}                                \addplot coordinates {                 (1, 0.2064)                 (2, 0.3961)                 (3, 0.5961)                 (4, 0.7961)}; \addlegendentry[text width=45pt, text depth=]{legend a}             \addplot coordinates {                 (1, 0.3064)                 (2, 0.4961)                 (3, 0.6961)                 (4, 0.8961)}; \addlegendentry[text width=65pt, text depth=]{lengend b}     \end{axis}  \end{tikzpicture} \end{document}
29209
I used the excellent code from TUGBoat issue 34 mentioned in this post  and was very happy until I tried to use it with logarithmic axis. The problem seems to be that the values stored in \pgfplots@data@xmin etc. are logarithmic.  \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document}      % automatically save the min and max value of the data     % this part is crucial for me since I do not want to find the min and max values manually in a large data file.     \makeatletter     \def\pgfplotsdataxmin{\pgfplots@data@xmin}     \def\pgfplotsdataxmax{\pgfplots@data@xmax}     \def\pgfplotsdataymin{\pgfplots@data@ymin}     \def\pgfplotsdataymax{\pgfplots@data@ymax}     \makeatother      % This adds the min and max values found above as extra ticks     \pgfplotsset{tufte extra ticks/.style={             extra x ticks={                 \pgfplotsdataxmin,                 \pgfplotsdataxmax             },             extra y ticks={                 \pgfplotsdataymin,                 \pgfplotsdataymax             },     }}        \pgfplotsset{         range frame/.style={             tick align=outside,             axis line style={opacity=0},             after end axis/.code={                 \draw ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmin,0}) -- ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmax,0});                 \draw ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymin}) -- ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymax});             }         }     }      \begin{tikzpicture}     \begin{axis}[     range frame,     xlabel={$L$ [H]},     ylabel={$\hat{I}_{DM}$ [A]},     axis lines*=left,     ymin=0.41,     ytick={0.7,0.9,...,1.5},     xtick={1.5e-3,2e-3,2.5e-3},     tufte extra ticks,     xmode=log, % &lt;- comment this out to get a working example     ]     \addplot +[black, mark options=fill=black] coordinates {(948e-6,1.61981) (1.5e-3,1.02377) (2e-3,0.769047) (2.5e-3,0.614994) (3.2e-3,0.503511)};     \end{axis}     \end{tikzpicture} \end{document}   Is there a way to solve this problem if one or both axis are in log-mode?  Edit: tufte extra ticks has the purpose to create a tick for the minimal and maximal value of each axis as in the image below.
110331
Please behold this MWE (compat is at 1.13, so by default the coordinates are in axis cs:):   \documentclass[border=10pt]{standalone} \usepackage{tikz} \usepackage{pgfplots}\pgfplotsset{compat=1.13} \begin{document}  \begin{tikzpicture}[     ]      \begin{axis}[         xmin=0, xmax=1500,            ymin=60, ymax=100,         axis y line* = right,         axis x line = none,         clip mode = individual,     ]         %\addplot [domain=0:1500] {97-x/150};         \addplot [domain=0:1500] {x/15};         \draw [green, &lt;-] (600, 93) -- ++(0,-1.5);         \draw [red,  &lt;-] (600, 93) -- (600, 93-1.5);     \end{axis} \end{tikzpicture} \end{document}   The two draw commands executes perfectly and they give the same arrow, so you really see just one:    If you now comment out the \addplot and use the previous one, i.e, like this:       \addplot [domain=0:1500] {97-x/150};     %\addplot [domain=0:1500] {x/15};   the relative coordinates \draw goes astray:     Where is my fault? Is that relative movements are not supposed to work in axis cs:? Why it depends on the previous plot?
89219
Could someone provide, please, a proof of the theorem below?  "Being $x$ and $b$ integers greater than $1$, which can not be represented as powers of the same basis (positive integer) and integer exponent, then the logarithm of $x$, in base $b$, is an irrational number."  Well... Assuming that the logarithm is a rational number $p/q$ ($p$ and $q$ are relatively prime integers), I know I can write $x^q = b^p$, but I can not conclude from this fact that $b$ and $x$ are powers of a same integer (and with integer exponent).
96277
Find $x$ for $4^{x-4} = 7$.  Answer I got, using log, was ${\log(7)\over 2\log(2)} + 4$  but the actual answer was ${\ln(7)\over2\ln(2)} + 4$  I plugged both in my calculator and turns out both are the equivalent value.  Anyways, is using either one of ln or log appropriate for this question? Obviously ln is when log has the base e, and log is when it has the base 10.   Final question: How do I know when to use which? that is which of ln or log is used when solving a question??  For example, if a question asks to find $x$ for $e^x = 100$, I will use $\ln$ since $\ln(e)$ cancels out.  If a question asks to find $2^x = 64$, i will use log since "$e$" isn't present in the question.  So is using either $\log$ or $\ln$ the same?
44298
From the original data, we know that they are nearly 0.087 rather that 0.087 x 10^-2. Why is there scientific notation (10^-2)? It looks ridiculous. Please help me figure it out. Thanks very much!   MWE:  \documentclass[border=5mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \definecolor{mycolor1}{rgb}{1,0,1}  \pgfplotstableread{ X           Y1 1    0.0873514639102964  2    0.0873656441069913  3    0.0873509320240032  4    0.0873490368814644  5    0.0873430960617957  6    0.0873334626756388  7    0.0873430596012905  8    0.0873485872405474  9    0.0873519301953318  10  0.0873474824394306 11  0.08735183859007     12  0.0873408783047386 13  0.0873439016123011 14  0.0873424452271129 15  0.0873452848079798 16  0.0873467228778811 17  0.087348210873026    18  0.0873464310394191 19  0.0873469131127228 20  0.0873449430894595 }\datatable  \pgfplotsset{     width=9cm,     height=6cm,     scale only axis,     xmin=0.5, xmax=20.5,     tick align = outside,     yticklabel style={/pgf/number format/fixed},   } \begin{tikzpicture}  \begin{axis}[     xtick={1,...,20},     ymin=0.08715,     ymax=0.08740,     ytick={0.08715,0.08720,0.08725,0.08730,0.08735,0.08740},     yticklabels={0.08715,0.08720,0.08725,0.08730,0.08735,0.08740},     xlabel={$x$},     ylabel={$y$},     y axis line style={mycolor1},     ytick style={mycolor1},     yticklabel style=mycolor1,     yticklabel style={/pgf/number format/fixed},     axis x line*=bottom,     axis y line*=left] \addplot [     color=mycolor1,     solid,     line width=1.5pt,     mark size=2.7pt,     mark=square*,     mark options={solid,fill=mycolor1}]     table [x=X, y=Y1]{\datatable}; \label{plot1} % So we can recall the plot style later on \end{axis} \end{tikzpicture}% \end{document}
50690
I am writing an algorithm where, given a model, I compute likelihoods for a list of datasets and then need to normalize (to probability) each one of the likelihood. So something like [0.00043, 0.00004, 0.00321] might be converted to may be like [0.2, 0.03, 0.77].   My problem is that the log likelihoods, I am working with, are quite small (for instance, in log space, the values are like -269647.432, -231444.981 etc). In my C++ code, when I try to add two of them (by taking their exponent) I get an answer of "Inf". I tried to add them in log-space , but again stumbled upon the same problem.  Can anybody share his/her expert opinion on this?
108928
I try to understand the actual intuition behind the logarithm properties and came across  that explains the multiplication and thereby also the division properties very nicely:     Suppose you have a table of powers of 2, which looks like this: (after revision)      $$\begin{array}{rrrrrrrrrr} 0&amp;1&amp;2&amp;3&amp;4&amp;5&amp;6&amp;7&amp;8&amp;9&amp;10\\ 1&amp;2&amp;4&amp;8&amp;16&amp;32&amp;64&amp;128&amp;256&amp;512&amp;1024 \end{array}$$      Each column says how many twos you have to multiply to get the number in that column.  For example, if you multiply 5 twos, you get $2\cdot2\cdot2\cdot2\cdot2=32$, which is the number in column 5.      Now suppose you want to multiply two numbers from the bottom row, say $16\cdot 64$.  Well, the $16$ is the product of 4 twos, and the $64$ is the product of 6 twos, so when you multiply them together you get a product of 10 twos, which is $1024$.   I found that very helpful to understand the actual proofs for this property.  I still struggle to get the idea behind the change of base rule. I'm familiar with the proof that goes like:  $$\log_a x = y \implies a^y = x$$ $$\log_b a^y = \log_b x$$ $$y \cdot \log_b a = \log_b x$$ $$y = \frac{\log_b x}{\log_b a}$$  But can somehow provide a explanation in the style of the quoted answer why this actually works?
58545
I'm trying to plot data with a logarithmic y-axis and restricting the y-data to a specified domain, but compilation fails for a reason I don't understand. This is the code:  \documentclass{standalone} \usepackage{pgfplots} \begin{document}% \begin{tikzpicture} \begin{axis}[ymode=log, restrict y to domain=1:6] \addplot coordinates {(0, 1.1e1) (1, 1.7e3) (2, 0.0e0) (2, 3.4e7) (4, 8.1e5)}; \end{axis} \end{tikzpicture} \end{document}   Running it results in an error message:  ! Missing number, treated as zero. &lt;to be read again&gt;                     i l.6 ..., 1.7e3) (2, 0.0e0) (2, 3.4e7) (4, 8.1e5)};   According to the pgfplots manual for version 1.5.1 (29 December 2011), page 272 (about restrict x/y/z to domain), For logarithmic axes, min and max are logs of the respective values. If I disable either the logarithmic y-axis or the domain-restriction, the code runs successfully and output is as expected (but not as desired).  Software versions:   pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011) (format=pdflatex 2012.5.30) pgfplots 2011/12/29 v1.5.1 (git show 1.5.1-4-g53e640f )  tikz 2010/10/13 v2.10 (rcs-revision 1.76).   What's going on? What am I doing wrong? Or is this a bug?
4832
I managed to create a simple linear plot with pgfplots-manual (chapter 4.5.1)    Now I want to replace the values of x-axis (1,2,3,4) with text, e.g.Test A, Test B, Test C, Test D. How can I do such a configuration?  MWE:       \documentclass[12pt,ngerman]{article}     \usepackage{pgfplots}     \pgfplotsset{width=7cm,compat=1.10}      \begin{document}      \begin{tikzpicture}     \begin{axis}         [         xlabel={Test},         ylabel={Mean}         ]     \addplot+[sharp plot] coordinates     {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};     \end{axis}     \end{tikzpicture}      \end{document}
77293
I realize that I lack any numerical intuition for logarithms. For example, when comparing two logarithms like $\log_78$ and $\log_89$, I have to use the change-of-base formula and calculate the values with a calculator in order to determine which of the two is larger.  Can anyone demonstrate an algebraic/analytic method to find out which of the two is larger without using a calculator?
77014
Why must the base of a logarithm be a positive real number not equal to 1? and why must $x$ be positive?  Thanks.
78222
pgfplots is not quite comfortable plotting sqrt(x) near x=0. The graphic can be improved by setting samples=2000 (not less), but this seems overkill to me.  Is there a way to plot x as a function of y, while keeping the x axis horizontal and the y axis vertical? This would solve the issue of plotting sqrt(x) by simply replacing it with x=y^2.  \documentclass{article}  \usepackage{pgfplots}  \begin{document}  \begin{tikzpicture}  \begin{axis}   \addplot[] {sqrt(x)};   \addplot[] {-sqrt(x)};  \end{axis} \end{tikzpicture}  \end{document}
23899
I would like to add a plot to a pgfplots figure, but such that it doesn't change the automatically computed limits. for example:  \documentclass{article} \usepackage{tikz,pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}%[ymin=-6,ymax=6] \addplot+ {x}; \addplot+ {x^2}; \end{axis} \end{tikzpicture} \end{document}   As written, the secont plot alters the limits. I could manually specify the limits (by removing the comment), but that's precisely what I want to avoid. Is there an option for this? I've found the forget plot option, but that's not quite what I need.
97494
Originally in my code, I had  xtick={-2*pi, -(3/2)*pi, -(1/2)*pi, (1/2)*pi,(3/2)*pi, 2*pi},  to put tick marks at integral multiples of $pi/2$.  It would not compile.  I had to replace it with cumbersome decimal approximations.  Why won't the code compile with expressions like pi?  To specify width of the x-axis in the axis environment, I used xmin=-2*pi, and xmax=2*pi,, and to specify the domain of the cosine function, I used domain=-2*pi:2*pi.  \documentclass{amsart} \usepackage{mathtools}  \usepackage{tikz} \usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}  \usepackage{pgfplots} \pgfplotsset{compat=1.11}    \begin{document}  \begin{tikzpicture} \begin{axis}[width=4.5in,clip=false,     xmin=-2*pi,xmax=2*pi,     ymin=-1.25,ymax=1.25,     axis lines=middle,     %xtick={-2*pi, -(3/2)*pi, -pi, -(1/2)*pi, (1/2)*pi, pi, (3/2)*pi, 2*pi},     xtick={-6.28318, -4.7123889, -3.14159, -1.5708, 1.5708, 3.14159, 4.7123889, 6.28318},     xticklabel style={font=\footnotesize,fill=white},     xticklabels={$-2\pi$,,$-\pi$,,,$\pi$,,$2\pi$},     ytick={-1},     yticklabel style={font=\footnotesize,fill=white},     yticklabels={$-1$},     extra y ticks={1},     extra y tick labels={$1$},     extra y tick style={yticklabel style={font=\footnotesize,fill=white,anchor=south east}},     ticklabel style={font=\footnotesize,fill=white},     axis line style={latex-latex},     axis line style={shorten &gt;=-7.5pt, shorten &lt;=-7.5pt},     xlabel style={at={(ticklabel* cs:1)},anchor=north west},     ylabel style={at={(ticklabel* cs:1)},anchor=south west} ]  \addplot [samples=501,mark=none, thick, red,domain=-2*pi:2*pi] {cos(deg(x))};  \end{axis} \end{tikzpicture}  \end{document}