我在网上找到了这个图/图像。我需要稍微改变一下框的值,并希望使用 PGFPlots 以更好的质量绘制它。
这是我尝试的代码:
\begin{tikzpicture}
\begin{axis}[
title={Title},
xlabel={Voltage [V]},
ylabel={Temperature [°C]},
xmin=0, xmax=10,
ymin=-15, ymax=300,
xtick={0,2,4,6,8,10},
ytick={0,50,100,150,200,250,300},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\fill [red](axis cs:0,-15) rectangle (axis cs:2.5,300);
\end{axis}
\end{tikzpicture}
出现的问题:
- 轴的缩放
- 区域标签(矩形)
- 图内的网格
有没有办法在 PGFPlots 中解决这三个点?
答案1
所以你的意思是类似于...(其余的应该不是什么大问题。但由于你有点不具体,我不想在这里猜测。)
% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use `compat' level 1.11 or higher so coordinates don't have to be
% prefixed with `axis cs:' (any more)
compat=1.11,
}
\begin{document}
\begin{tikzpicture}[
region/.style={
draw=black!50,
dashed,
},
Node/.style={
midway,
red,
},
declare function={
xmin=0;
xmax=10.5;
ymin=-50;
ymax=300;
},
]
\begin{axis}[
xlabel={Voltage in V},
ylabel={Temperature in ${}^\circ$C},
xmin=xmin,
xmax=xmax,
ymin=ymin,
ymax=ymax,
axis background/.style={
fill=red!10,
},
extra x ticks={3},
extra y ticks={60},
]
\draw [region,fill=green!20] (3,0) rectangle (4.2,60)
node [midway,green] {1};
\draw [region]
(xmin,ymin) rectangle (2.5,ymax) node [Node] {2}
(4.5,ymin) rectangle (6.5,60) node [Node] {3a}
(2,ymin) rectangle (4.5,-2) node [Node] {3b}
(2.5,60) rectangle (6.5,130) node [Node] {4}
(6.5,ymin) rectangle (xmax,130) node [Node] {5}
(2.5,130) rectangle (xmax,210) node [Node] {6}
(2.5,210) rectangle (xmax,ymax) node [Node] {7}
;
\end{axis}
\end{tikzpicture}
\end{document}