0

So i want to plot using PGFPlots but somehow i get bad locking plots. In Excel it looks like this:

Excel

If i try to make it with PGFPlots I get a super bad looking plot. What i want to have it the x axis simmilar to the plot in excel, but if i change the xtick or xticklabels i get errors.... Anyone got a suggestion ?

My Latexcode:

\begin{figure}
\centering
\begin{tikzpicture}
  \pgfplotsset{
      scale only axis,
  }
  \begin{axis}[
  width=0.85\linewidth,
  height=8cm,
    xlabel=$A$,
    ylabel=$B$,
 ]
    \addplot[only marks, color=blue]
    coordinates{
      (2.5e-3,20.29)
      (1.25e-3,21.46)
      (6.3e-4,27.61)
      (3.2e-4,42.23)
      (1.5e-4,57.95)
      (0.7e-4,68.51)
      (4e-05,70.15)
    }; 
  \end{axis}
\end{tikzpicture}
\end{figure}
Juan Castaño
  • 28,426
Tobbbe
  • 5

1 Answers1

0

I found a solution here. You have to define the precision and to remove the scaling factor.

\documentclass[border=5pt]{standalone}

\usepackage{pgfplots} \pgfplotsset{ compat=newest, scaled x ticks=false, xticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=5 }, }

\begin{document} \begin{tikzpicture} \pgfplotsset{ scale only axis, } \begin{axis}[ width=0.85\linewidth, height=8cm, xlabel=$A$, ylabel=$B$, ] \addplot[only marks, color=blue] coordinates{ (2.5e-3,20.29) (1.25e-3,21.46) (6.3e-4,27.61) (3.2e-4,42.23) (1.5e-4,57.95) (0.7e-4,68.51) (4e-05,70.15) }; \end{axis} \end{tikzpicture} \end{document}

enter image description here

Excelsior
  • 2,322
  • thanks alot for your answer. funny enough, your mwe is working for me, however if i copy paste it into my document it messes everything up and i get 20 or more labels on my x axis.... – Tobbbe Apr 01 '21 at 13:02
  • so you only want the 6 xlabels? – Excelsior Apr 01 '21 at 13:08
  • yeah. still i dont know why i get your result in a new file, and get a super bad looking plot in my main document..

    any idea to reduce the amount of xlabels manually ?

    – Tobbbe Apr 01 '21 at 13:09
  • Just add xtick={0,0.0005,...,0.0025}, and xticklabels={0,0.0005,0.001,0.0015,0.002,0.0025}, in your axis environment – Excelsior Apr 01 '21 at 13:12
  • thats does the job! great thanks alot. I still got no idea why its not working automaticly but its absolutly fine that way. thanks :)! – Tobbbe Apr 01 '21 at 13:25
  • Would be interesting if you could ask another question with the problem you have with the number of xlabels, because i don't have the issue. But its up to you, since it works for you with my approach. – Excelsior Apr 01 '21 at 13:29