如何使用不遵循全域選項的最少資料校正 PGFPLOT 圖?

如何使用不遵循全域選項的最少資料校正 PGFPLOT 圖?

我的測試數據不完整,如 MWE 中所示。我想使用圖中的所有(少數)可用數據點,即銅的(55.16,0.08),但該圖沒有考慮到它。此外,諸如逗號分隔符號之類的全域選項不起作用(它僅適用於本機y =0.5 y 刻度標籤,但不適用於新增的y 刻度標籤。(但是,它們與手冊中的其中一個圖配合得很好,因此問題在於我的數據和/或繪圖選項,我也無法在繪圖中使用“僅標記”選項,這可能是有意義的。

\documentclass[]{scrartcl}
\usepackage{siunitx}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepackage{pgfplotstable}


\pgfplotsset{compat=newest,
every linear axis/.append style={
/pgf/number format/use comma,
/pgf/number format/fixed,
}}

\begin{document}

\begin{filecontents}{data-W.csv}
{Stress};{Aluminium};{Copper}
3.44;0.0015;0.001
6.89;0.1;0.002
10.34;0.2; 
11.72; ;0.0068
13.79; ; 
15.51;0.5; 
17.24; ; 
20.68;1;0.01
24.13; ; 
27.58; ; 
31.03; ; 
34.47; ;
37.92; ; 
41.37; ;0.04
44.82; ; 
48.26; ; 
55.16; ;0.08
\end{filecontents}

\pgfplotstableread[col sep=semicolon]{data-W.csv}{\datatableW}

\begin{tikzpicture}
\begin{axis}[
height=.5\textwidth, width=\textwidth,
xticklabel style= {font={\small}},
grid=both,
%xticklabels from table={\datatableW}{[index]0}, %does not accept plot settings
 extra y ticks={.1,.3,.5,.7,.9},  % Did not accept global option but now does
%extra y tick labels={.1,.3,.5,.7,.9} % not necessary now
xlabel={Stress (\si{\mega\pascal})}, 
ylabel={Relaxation (\%)}, 
legend entries={Pure aluminium,Copper}, ]
\addplot [blue,only marks]  table [ 
x index =0, y index=1] {\datatableW};
% x expr=\coordindex, x index =0,{\datatableW}; % Incorrect
\addplot [red,]  table [
x index =0, 
%x expr=\coordindex, x index =0, % incorrect
y index=2] {\datatableW}; 
\end{axis} \end{tikzpicture}

\end{document}

答案1

情節選項中的幾個錯誤(以及一般情節設定中的矛盾)造成了問題。我已經編輯了程式碼以突出顯示並更正它們。我仍然不清楚為什麼這個選項

xticklabels from  table={\datatableW}{[index]0}

似乎不接受全局劇情設置,但是去掉它讓劇情更普通更好看,更有邏輯性。

相關內容