我正在尝试通过改变 X 轴和 Y 轴列数据的原始数据的符号来绘制数据,我该如何进行操作,我有大量数据,所以可以写入,所以我尽量减少我的问题。感谢您的任何建议。改变每列数据的符号后,我的数据将如下所示
Ax By
-1 -0.5
-2 1
-3 -1.5
我想不用手动操作,下面是我的 MWE
\begin{filecontents}{data.txt}
Ax By
1 0.5
2 -1
3 1.5
\end{filecontents}
\documentclass[10pt]{article}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\newcommand{\mydataOAA}{data.txt}
\begin{document}
\hspace*{-3cm} \begin{tikzpicture}[scale=1.9]
\begin{axis}[
%scaled y ticks=base 10:6,
%x dir=reverse,
%y dir=reverse,
xticklabel style={black} ,
yticklabel style={black} ,
xlabel=\color{black}-$\textrm{V}_{\hspace*{-0.5mm}\tiny\textrm{d}}$($V$),
ylabel=\color{black}-$\textrm{I}_{\tiny\textrm{d}}$($A$),ylabel near ticks,legend pos=north west,legend style={font=\fontsize{4}{5}\selectfont}]
\addplot[mark=line,brown] table [y=By, x=Ax, col sep=space]{\mydataOAA};
\addlegendentry{\color{black}$V_{g}$=0V}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这是需要的吗?
\begin{filecontents}{data.txt}
Ax By
1 0.5
2 -1
3 1.5
\end{filecontents}
\documentclass[10pt]{article}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\newcommand{\mydataOAA}{data.txt}
\begin{document}
\hspace*{-3cm} \begin{tikzpicture}[scale=1.9]
\begin{axis}[
%scaled y ticks=base 10:6,
%x dir=reverse,
%y dir=reverse,
xticklabel style={black} ,
yticklabel style={black} ,
xlabel=\color{black}-$\textrm{V}_{\hspace*{-0.5mm}\tiny\textrm{d}}$($V$),
ylabel=\color{black}-$\textrm{I}_{\tiny\textrm{d}}$($A$),ylabel near ticks,legend pos=north west,legend style={font=\fontsize{4}{5}\selectfont}]
\addplot[mark=line,brown] table [y expr=-\thisrow{By}, % <----------
x expr =-\thisrow{Ax}, % <---------
col sep=space]{\mydataOAA};
\addlegendentry{\color{black}$V_{g}$=0V}
\end{axis}
\end{tikzpicture}
\end{document}
答案2
您可以利用该x expr
功能(和朋友)来实现这一点。请查看代码以了解如何明确使用它。(请注意,我从您的代码中删除了所有不相关的内容。)
% used PGFPlots v1.17
\begin{filecontents}{data.txt}
Ax By
1 0.5
2 -1
3 1.5
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [
% for named columns you can use
x expr={-1*\thisrow{Ax}},
% for unnamed columns (i.e. there is no header row) you can use
% (Please note that the numbering starts from 0.)
y expr={-1*\thisrowno{1}},
] {data.txt};
\end{axis}
\end{tikzpicture}
\end{document}