我有一个较小的图,我想用 将其嵌入到我的文本中0.5\textwidth
。这破坏了字体大小和信息之间的平衡,所以我将字体大小更改为\tiny
。但现在刻度到轴和标签到刻度之间的距离看起来太大了,所以我通过yticklabel style = {xshift=2pt}
和移动了两者ylabel shift = -4pt
。但这会破坏 pgf-plot 计算,因为我的图形周围的空白增加了。
代码如下:
\begin{tikzpicture}[framed]
\definecolor{chocolate19310053}{RGB}{193,100,53}
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{darkslategray348596}{RGB}{34,85,96}
\begin{axis}[
height=0.62*0.5\figwidth,
tick align=outside,
tick pos=left,
width=0.5\figwidth,
x grid style={darkgray176},
xlabel={clean accuracy},
xmin=84.753, xmax=97.227,
xtick style={color=black},
y grid style={darkgray176},
ylabel={new test accuary},
ymin=57.6975704182106, ymax=98.515353789609,
ytick style={color=black},
font=\tiny,
ylabel shift = -4pt,
yticklabel style = {xshift=2pt},
xlabel shift = -4pt,
xticklabel style = {yshift=2pt},
mark size= 1.0pt,
]
\addplot [
mark=*,
only marks,
scatter,
scatter/@post marker code/.code={%
\endscope
},
scatter/@pre marker code/.code={%
\expanded{%
\noexpand\definecolor{thispointdrawcolor}{RGB}{\drawcolor}%
\noexpand\definecolor{thispointfillcolor}{RGB}{\fillcolor}%
}%
\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%
},
visualization depends on={value \thisrow{draw} \as \drawcolor},
visualization depends on={value \thisrow{fill} \as \fillcolor}
]
table{%
x y draw fill
85.32 59.8406374501992 145,71,46 145,71,46
94.87 74.4223107569721 145,71,46 145,71,46
96.66 77.9282868525897 145,71,46 145,71,46
95.83 77.2111553784861 145,71,46 145,71,46
95.08 77.3705179282869 145,71,46 145,71,46
94.97 77.7689243027888 145,71,46 145,71,46
93.24 72.8286852589641 145,71,46 145,71,46
93.1 71.9521912350598 145,71,46 145,71,46
94.75 73.5458167330677 145,71,46 145,71,46
94.77 75.2191235059761 145,71,46 145,71,46
92.23 78.5657370517928 145,71,46 145,71,46
92.23 72.7490039840637 145,71,46 145,71,46
};
\addplot [semithick, chocolate19310053]
table {%
85.3199996948242 61.5563278198242
96.6600036621094 78.7848129272461
};
\addplot [semithick, darkslategray348596]
table {%
85.3199996948242 85.3199996948242
96.6600036621094 96.6600036621094
};
\end{axis}
\end{tikzpicture}
结果是:
答案1
您不需要像之前那样改变绘图参数来使图形适合宽度0.5\textwidth
。TikZ
因此pgfplots
可以选择将图形缩放到所需的高度/宽度比。
没有序言和其他信息,我只是将您的代码插入默认文档并注释掉一些导致编译错误的行。使用paracol
定义两列 about0.5\textwidth
和scale
选项,您的图可以紧密贴合在分配的列内。
因此该代码应该可以工作:
\documentclass[a4paper,11pt]{article}
\usepackage[margin=2.0cm]{geometry}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}
\usepackage{lipsum}
\usepackage{paracol}
\begin{document}
\lipsum[1][1-4]
\columnratio{0.5,0.5}
\begin{paracol}{2}
\noindent % to prevent indentation on first sentence
\begin{tikzpicture}[framed, scale=0.95]
\definecolor{chocolate19310053}{RGB}{193,100,53}
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{darkslategray348596}{RGB}{34,85,96}
\begin{axis}[
height=0.62*0.5\textwidth, %<= \figwidth causes errors
tick align=outside,
tick pos=left,
width=0.5\textwidth, %<= \figwidth causes errors
x grid style={darkgray176},
xlabel={\large clean accuracy},
xmin=84.753, xmax=97.227,
xtick style={color=black},
y grid style={darkgray176},
ylabel={\large new test accuary},
ymin=57.6975704182106, ymax=98.515353789609,
ytick style={color=black},
font=\small,
% ylabel shift = -4pt, %<= maybe for finetuning position
yticklabel style = {xshift=2pt},
% xlabel shift = -4pt, %<= maybe for finetuning position
xticklabel style = {yshift=2pt},
mark size= 1.0pt,
]
\addplot [
mark=*,
only marks,
scatter,
scatter/@post marker code/.code={%
\endscope
},
scatter/@pre marker code/.code={%
\expanded{%
\noexpand\definecolor{thispointdrawcolor}{RGB}{\drawcolor}%
\noexpand\definecolor{thispointfillcolor}{RGB}{\fillcolor}%
}%
\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%
},
visualization depends on={value \thisrow{draw} \as \drawcolor},
visualization depends on={value \thisrow{fill} \as \fillcolor}
]
table{%
x y draw fill
85.32 59.8406374501992 145,71,46 145,71,46
94.87 74.4223107569721 145,71,46 145,71,46
96.66 77.9282868525897 145,71,46 145,71,46
95.83 77.2111553784861 145,71,46 145,71,46
95.08 77.3705179282869 145,71,46 145,71,46
94.97 77.7689243027888 145,71,46 145,71,46
93.24 72.8286852589641 145,71,46 145,71,46
93.1 71.9521912350598 145,71,46 145,71,46
94.75 73.5458167330677 145,71,46 145,71,46
94.77 75.2191235059761 145,71,46 145,71,46
92.23 78.5657370517928 145,71,46 145,71,46
92.23 72.7490039840637 145,71,46 145,71,46
};
\addplot [semithick, chocolate19310053]
table {%
85.3199996948242 61.5563278198242
96.6600036621094 78.7848129272461
};
\addplot [semithick, darkslategray348596]
table {%
85.3199996948242 85.3199996948242
96.6600036621094 96.6600036621094
};
\end{axis}
\end{tikzpicture}
\switchcolumn
\lipsum[2]
\end{paracol}
\medskip
\hrule
\end{document}