2

I am adding data points onto a plotted graph and adding a trend line y=mx+b equation taken from Excel.

However, the output looks ugly and I am not sure why.

The trend line just stops, the maximum number on the y-axis is missing, and when this prints, the light coloured grid appears dull or not appear at all. Another issue is Case 2 at 60 Ohms will be next part of the data points, but I am going on a tangent here, formatting the three additional tables/graphs I can figure out later on when I get the graph looking correct.

Essentially, any suggestions in making this look more ideal if that means prettier or better is appreciated.

\documentclass{article}

\usepackage[letterpaper, portrait, margin=2cm]{geometry}
\usepackage{pgfplots}
\usepackage{booktabs}


\begin{document} 
\section{Results}
\noindent
\begin{tabular}{@{}cc@{}}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[
title={Case 1 at 40 $\Omega$},
xlabel={Electric Current (mA)},
ylabel={Electric Potential (V)},
xmin=0, xmax=50, 
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!70},
minor tick num=5,
legend pos=north west,
ymajorgrids=true,
xmajorgrids=true,
yminorgrids=true,
xminorgrids=true,
grid style=dashed
]

\addplot[only marks, color=blue]
 coordinates {
  (15.61,0.598)
    (23.99,0.924)
    (30.30,1.173)
    (44.70,1.718)
    (14.55,0.561)
    (16.66,0.642)
    (46.80,1.799)
    (143.6,5.555)
    (28.22,1.086)
    (18.19,0.701)
 };
  \addplot[no marks, thick, color=red] {0.0383*x - 0.0041 };
\end{axis}
\end{tikzpicture}

\begin{tabular}{c c c}
\toprule[1.5pt]
{\bf Electric Current (mA) } & {\bf Electric Potential (V)} \\
\midrule
15.61 & 0.598 \\
\midrule
23.99 & 0.924 \\
\midrule
30.30 & 1.173 \\
\midrule
44.70 & 1.718 \\
\midrule
14.55 & 0.561 \\
\midrule
16.66 & 0.642 \\
\midrule
46.80 & 1.799 \\
\midrule
143.6 & 5.555 \\
\midrule
28.22 & 1.086 \\
\midrule 
18.19 & 0.701 \\
\bottomrule[1.5pt]
\end{tabular}
\end{tabular}
\end{document}

40-ohms

5

Make graph prettier ... this is matter of taste. Anyway, see if the following result is acceptable:

enter image description here

In your MWE I add domain for trend line, define ymin and ymax, add missing & in table, simplify grids style definitions, redesign table:

\documentclass{article}

\usepackage[letterpaper, portrait, margin=2cm]{geometry}
\usepackage{pgfplots}
\usepackage{booktabs}


\begin{document}
\section{Results}
    \begin{center}
\begin{tabular}{@{}c@{\qquad}c@{}}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[
title={Case 1 at 40 $\Omega$},
xlabel={Electric Current (mA)},
ylabel={Electric Potential (V)},
xmin=0, xmax=50,
ymin=0, ymax=2,% <-- added
grid=both,
grid style={line width=.1pt, draw=gray!50},
major grid style={line width=.2pt,draw=gray},
minor tick num=5,
legend pos=north west,
%ymajorgrids=true,
%xmajorgrids=true,
grid=both,
%minorgrid,
%xminorgrids=true,
grid style=dashed
]
\addplot[only marks, color=blue]
 coordinates {
  (15.61,0.598)
    (23.99,0.924)
    (30.30,1.173)
    (44.70,1.718)
    (14.55,0.561)
    (16.66,0.642)
    (46.80,1.799)
    (143.6,5.555)
    (28.22,1.086)
    (18.19,0.701)
 };
  \addplot[no marks, thick, color=red, domain=0:50] {0.0383*x - 0.0041};
\end{axis}
\end{tikzpicture}
&
\begin{tabular}{c c}
\toprule
\textbf{Electric}       & \textbf{Electric}         \\
\textbf{Current (mA)}   & \textbf{Potential (V)}    \\
\midrule
15.61 & 0.598 \\
23.99 & 0.924 \\
\addlinespace[3pt]
30.30 & 1.173 \\
44.70 & 1.718 \\
\addlinespace[3pt]
14.55 & 0.561 \\
16.66 & 0.642 \\
\addlinespace[3pt]
46.80 & 1.799 \\
143.6 & 5.555 \\
\addlinespace[3pt]
28.22 & 1.086 \\
18.19 & 0.701 \\
\bottomrule
\end{tabular}
\end{tabular}
    \end{center}
\end{document}
  • Yeah I know "prettier" is subjective, didn't know how else to describe it since it was broken, but forgot fix the outlier, where the x=143.6 skews the graph, we just had a lecture on data skewing that we shouldn't remove data because it was a fluke... (see above edit) – Jonathan Weinraub Oct 30 '16 at 5:46

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.