更改 PGFPlots 中对数刻度的步骤并删除选定系列的标记

更改 PGFPlots 中对数刻度的步骤并删除选定系列的标记

1) 因此我希望增加 x 轴的步长,因为目前它看起来很混乱。不幸的是,这是一个对数对数图,因此通常

xtick={-5,0,5},

不起作用。目前,它看起来像这样(出于隐私考虑,省略了图表中的主要内容)。

在此处输入图片描述

我的 MWE 是这样的,但我想如果没有数据文件本身它就无法工作,如果需要的话我可以提供数据文件,但我认为这很简单。

\documentclass[letterpaper,12pt]{article}
\usepackage[margin=0.5 in,landscape]{geometry}
\usepackage[justification=centering]{caption}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplotstable,pgfplots}
%\renewcommand{\familydefault}{\sfdefault}
\usepackage{mathptmx}
%\usepackage{sansmath} % Enables turning on sans-serif math mode, and using other environments
%\sansmath % Enable sans-serif math for rest of document
%\usepackage[math]{blindtext}
\pagestyle{empty}
\pgfplotsset
{
    compat = newest,
    every axis/.append style={semithick},
    major tick length=7pt,
    minor tick length=3pt,
    tick style={semithick,black},
    width= \textwidth,
    height= \textheight
}
\pgfplotstableread[col sep = comma]{dat.csv}\mydata

\begin{document}
\begin{figure}
    \begin{tikzpicture}
    \begin{loglogaxis}[
    xlabel=Re,
    ylabel=Fanning friction factor \textit{f},
    %y label style={rotate=-90},
    legend pos=south west,
    legend columns=1,
    legend style={draw=none}
    %no markers
    ]
    ‎\addplot table [y=fexpSS, x=ReSS, mark=only marks]{\mydata};‎
    ‎\addlegendentry{SS Experimental}
    \addplot table [y=fchurchSS, x=ReSS, mark=none]{\mydata};‎
    ‎\addlegendentry{SS Churchill}‎
    ‎\addplot table [y=fexpGalv., x=ReGalv., only marks]{\mydata};‎
    ‎\addlegendentry{Galv. Exp}‎
    ‎\addplot table [y=fchurchGalv., x=ReGalv., mark=none]{\mydata};‎
    ‎\addlegendentry{Galv. Churchill}‎
    ‎\addplot table [y=fexpCu, x=ReCu, only marks]{\mydata};‎
    ‎\addlegendentry{Cu Exp}
    ‎\addplot table [y=fchurchCu, x=ReCu, mark=none]{\mydata};‎
    ‎\addlegendentry{Cu Churchill}‎
    ‎\addplot table [y=fexpPVC, x=RePVC, only marks]{\mydata};‎
    ‎\addlegendentry{PVC Exp}
    ‎\addplot table [y=fchurchPVC, x=RePVC, mark=none]{\mydata};‎
    ‎\addlegendentry{PVC Churchill}‎
    ‎\addplot table [y=blasius, x=RePVC, mark=none]{\mydata};‎
    ‎\addlegendentry{Blasius Equation}‎
    \end{loglogaxis}
    \end{tikzpicture}
    \caption{Friction factors versus Reynolds Number for different pipes}
\end{figure}

\end{document}

顺便说一下,我也想控制 y 轴的步数和最小值/最大值。

CSV 文件可在此处下载:https://1drv.ms/u/s!AnPuH_uDwkPFgo58-JfHJHs4CE4c6w

2) 我还想从图例中删除带有线条的系列的标记(即,8 个系列,其中的线条穿过点),并希望从图例中删除只有点而没有线条的 4 个系列的线条。我尝试了解决方案这里但它删除了所有标记,所以不可行。我在 Excel 中所做的操作是可行的,例如下面所示。

在此处输入图片描述

3) 我想在这里的 f 前加一个逗号,但如果我这样做,它就会加载失败。有人有什么想法吗?

ylabel=Fanning friction factor \textit{f},

答案1

对于 1),您可以使用例如xtickten+ some extra x ticks
对于 2),您几乎做对了。您只需将“标记”选项提供给 的可选参数\addplot,而不是 的可选参数table
对于 3),您只需用花括号将标签括起来,这样逗号就不会被误解为选项的分隔符。

然后我又做了一些小改动。为此,请查看代码中的注释。

(现在剩下的问题是,“Cu Churchill”线几乎完全位于“PVC Churchill”线后面。可以通过将移动dashed到“PVC Churchill”或使用dasheddotted线作为最后两行来避免这种情况。)

% used PGFPlots v1.14
% (the data file must be downloaded from the link in the question
%  <http://tex.stackexchange.com/q/337900>)
\documentclass[letterpaper,12pt]{article}
\usepackage[margin=0.5 in,landscape]{geometry}
\usepackage{pgfplots,pgfplotstable}
    \usetikzlibrary{pgfplots.colorbrewer}
    \pgfplotsset{
        compat=1.3,
        every axis/.append style={semithick},
        major tick length=7pt,
        minor tick length=3pt,
        tick style={semithick,black},
        width=\textwidth,
        height=\textheight,
    }
\begin{document}
        \pagestyle{empty}
    \begin{figure}
        \begin{tikzpicture}
                \pgfplotstableread[col sep=comma]{dat.csv}\mydata
            \begin{loglogaxis}[
                % put `xlabel' in math mode because "Re" is a variable
                % (same for "f" in `ylabel')
                xlabel=$Re$,
                % to use a comma inside the label, surround the label in brackets
                % so the comma isn't misinterpreted being an option separator
                ylabel={Fanning friction factor, $f$},
                legend pos=south west,
                legend columns=1,
                legend style={draw=none},
                % added min and max values to know where to put the extra tick labels
                xmin=9e3,
                xmax=8e4,
                ymin=4e-3,
                ymax=1.2e-2,
                % added (main) ticks
                xtickten={4,5},
                ytickten={-3,-2,-1},
                % added extra ticks at the ends of the axes
                extra x ticks={9e3,8e4},
                extra y ticks={4e-3,1.2e-2},
                % use ColorBrewer cycle list
                cycle list/Set1-4,
            ]
                % moved "mark" options to the optional argument of `\addplot'
                % and added colors manually, so they match for the same "set"
                ‎\addplot+ [only marks,Set1-A] table [x=ReSS,y=fexpSS]          {\mydata};‎
                \addplot+ [mark=none,Set1-A]  table [x=ReSS,y=fchurchSS]       {\mydata};‎
                ‎\addplot+ [only marks,Set1-B] table [x=ReGalv.,y=fexpGalv.]    {\mydata};‎
                ‎\addplot+ [mark=none,Set1-B]  table [x=ReGalv.,y=fchurchGalv.] {\mydata};‎
                ‎\addplot+ [only marks,Set1-C] table [x=ReCu,y=fexpCu]          {\mydata};‎
                ‎\addplot+ [mark=none,Set1-C]  table [x=ReCu,y=fchurchCu]       {\mydata};‎
                ‎\addplot+ [only marks,Set1-D] table [x=RePVC,y=fexpPVC]        {\mydata};‎
                ‎\addplot+ [mark=none,Set1-D]  table [x=RePVC,y=fchurchPVC]     {\mydata};‎
                ‎\addplot+ [mark=none,Set1-D,dashed]  table [x=RePVC,y=blasius] {\mydata};‎

                % moved legend here because (I think) it is much more clearly arranged
                \legend{
                    SS Experimental,
                    SS Churchill,‎
                    Galv. Exp,‎
                    Galv. Churchill,‎
                    Cu Exp,
                    Cu Churchill,‎
                    PVC Exp,
                    PVC Churchill,‎
                    Blasius Equation,
                }‎
            \end{loglogaxis}
        \end{tikzpicture}
        \caption{Friction factors versus Reynolds Number for different pipes}
    \end{figure}
\end{document}

该图显示了上述代码的结果

相关内容