我是乳胶方面的新手,从你那里学到了很多东西。有人能帮我做这个图吗?我完全被难住了。
到目前为止我只能这样做:
\documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,italian]{babel}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[backend=biber]{biblatex}
\usepackage{tikz}
\usetikzlibrary{calc,quotes,angles}
\usepgflibrary{arrows.meta}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}[name=plot,
xmin=0,
xmax=20,
ymin=0,
ymax=20,
yticklabels={,,},
xticklabels={,,},
ytick=\empty,
xtick=\empty,
axis line style={draw=none},
tick style={draw=none}
]
\addplot[black,mark=.] {1*x};
\addplot[black,mark=.] {4*x};
\addplot[black,dashed] {5*x-5};
\coordinate (A) at (5,1.25);
\coordinate (B) at (1.25,1.25);
\coordinate (C) at (5,20);
\draw[<->] (A) -- (C);
\draw[<->] (B) -- (A);
\end{axis}
\end{tikzpicture}
\caption{\textit{Plot name}}
\label{fig:plot_tag}
\end{figure}
\end{document}
我不知道为什么我定义坐标后它不显示垂直线:
\draw[<->] (A) -- (C);
\draw[<->] (B) -- (A);
答案1
这是一个开始。一些注释:
- 对于下面要用到的一些功能,必须使用兼容性设置,即。您可以根据需要
\pgfplotsset{compat=1.16}
将版本号调整为您自己的 版本。pgfplots
- 为了使轴线正确,绘图的限制已被调整为包含一些负值(
xmin,xmax,ymin,ymax
),轴线已被设置为原点,axis lines=middle
并且通过注释掉选项使轴可见draw=none
。 - 使用 打印轴标签的方式不同
axis lines=middle
。要恢复正常位置,可以使用ylabel near ticks
和xlabel near ticks
。但是,这并没有带来很好的定位,因此在下面的代码中使用 进行或多或少的手动放置at
。cs
轴的起点和终点的坐标分别介于 0 和 1 之间。设置anchor
指定标签相对于指定坐标的相对位置。 - 对于绘图,指定一个域来仅显示绘图的相关部分。
- 绘图使用命令
node
中的来标记addplot
。节点的位置介于 0 和 1 之间,表示范围的开始和结束。节点是手动旋转的,我不确定如何自动将它们与绘图对齐。 - 为 1 和 5 之间的虚线添加了伪图。
- 箭头上的标签是使用语句
node
中的规范添加的draw
,并带有一些定位选项。 - 我稍微缩短了标签,以便更好地适应
\scriptsize
用作字体大小的情况。或者,您可以考虑\tiny
使用大小,或者将标签移到更远、空间更大的位置。 - 最后说明:虽然
pgfplots
使用了一些功能,但需要进行大量自定义,而且它不是带有刻度和连续函数的“真实”绘图。因此,对于类似的绘图,最好只使用 TikZ 并手动将所有内容绘制为线条,这将使自定义更容易。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{calc,quotes,angles}
\usepgflibrary{arrows.meta}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{axis}[name=plot,
xmin=-2,
xmax=15,
ymin=-6,
ymax=23,
%yticklabels={,,},
%xticklabels={,,},
ytick=\empty,
xtick=\empty,
%axis line style={draw=none},
axis lines=middle,
xlabel={Air Mass flow},
ylabel={Compression Ratio},
%ylabel near ticks, % automatic placement, not used here
%xlabel near ticks, %
x label style={at={(axis description cs:0.9,0.2)},anchor=north east},
y label style={at={(axis description cs:0.1,0.7)},rotate=90,anchor=south},
tick style={draw=none}
]
\addplot[black,mark=.,domain=0:10] {1*x} node[pos=0.8,above,rotate=25] {\scriptsize surge line 1};
\addplot[black,mark=.,domain=0:6] {4*x} node[pos=0.8,above,rotate=60] {\scriptsize surge line 2};
\addplot[black,dashed,domain=0:5] {5*x-5};
\addplot[black,dashed,domain=1:5] {1};
\coordinate (A) at (5,1.25);
\coordinate (B) at (1.25,1.25);
\coordinate (A1) at (5,-1.25);
\coordinate (B1) at (1.25,-1.25);
\coordinate (C) at (5,20);
\draw[<->] (A) -- (C) node[near start,rotate=90,anchor=north,xshift=8mm] {\scriptsize compression ratio increase};
\draw[<->] (A1) -- (B1) node[midway,anchor=north] {\scriptsize air mass increase};
\draw[densely dotted] (A) -- (A1);
\draw[densely dotted] (B) -- (B1);
\end{axis}
\end{tikzpicture}
\end{document}
结果:
答案2
稍微简化了草图,删除了所有重复的库,考虑了加载pgfplots
和tikz
加载hyperref
包\url
。为了缩短图像代码,定义了两种样式,分别用于线上的节点和用于测量距离的箭头。
\documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[english,italian]{babel}
\usepackage{amsmath, amssymb}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[backend=biber]{biblatex}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0.5pt}
\fancyhead[]{}
\fancyhead[LO]{\nouppercase{\rightmark}}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyfoot{}
\fancyfoot[LO,RE]{\thepage}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\parindent 0ex
\usepackage{pgfplots}
\pgfplotsset{compat=1.16} % 1.17 is recent at time of writing answer
\usepgfplotslibrary{groupplots}
\usetikzlibrary{angles, arrows.meta,
calc,
quotes,}
\usepackage{hyperref} % it load url too
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
lbl/.style = {inner ysep=2pt, font=\scriptsize, text=black,
align=center, anchor=south east, rotate=#1},
arr/.style = {{Bar[width=3.2mm].Straight Barb[]}-{Straight Barb[].Bar[width=3.2mm]},
transform canvas={#1}}
]
\begin{axis}[name=plot,
xmin=-1, xmax=15,
ymin=-6, ymax=25,
xtick=\empty,
ytick=\empty,
axis lines=middle,
xlabel={Air Mass flow},
ylabel={Compression Ratio},
x label style={anchor=north east},
y label style={rotate=90,anchor=south east},
samples=2
]
\addplot[gray,domain=0:12] {x} node[lbl=25] {surge line 1};
\addplot[gray,domain=0:6] {4*x} node[lbl=60] {surge line 2};
%
\addplot[dashed,domain=0:5] {5*x-5};
\coordinate (A) at (1.25,1.25);
\coordinate (B) at (5,1.25);
\coordinate (C) at (5,20);
\coordinate (A1) at (5,-1.25);
\coordinate (B1) at (1.25,-1.25);
\draw[arr={yshift=-5mm}] (A) -- node[lbl=0, below] {air mass\\ increase} (B) ;
\draw[arr={xshift= 3mm}] (B) -- node[lbl=90, below] {compression\\ ratio increase} (C);
\draw[densely dotted, red] (A) -| (C);
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案3
我的解决方案没有pgfplots
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections,arrows.meta}
\begin{document}
\begin{tikzpicture}[line width=5pt,font=\Huge,
ds-1/.style={dash pattern=on 20pt off 10pt},
ds-2/.style={dash pattern=on 30pt off 10pt}]
\draw[-{Triangle[open]},name path=xa] (-4.5,0) -- (29.5,0)
node[below,very near end]{Air Mass Flow}; %x axis
\draw[-{Triangle[open]},name path=ya] (0,-5.5) -- (0,28)
node[sloped,above,pos=0.85]{Compression Ratio}; %y axis
\draw[domain=0:20,name path=sl1] plot (\x,1.175*\x)
node[sloped,above left,rotate=atan(1.175)]{surge line 1};
\draw[domain=0:11.5,name path=sl2] plot (\x,2.304*\x)
node[sloped,above left,rotate=atan(2.304),font=\Huge]{surge line 2};
\path[domain=-1:11.5,name path=dl] plot (\x,2.791*\x -4.209);
\fill[name intersections={of=sl1 and dl, by=p1},
name intersections={of=sl2 and dl, by=p2},
name intersections={of=dl and ya, by=py}](p1) circle[radius=8pt] (p2) circle[radius=8pt];
\draw[dashed,ds-2] (p2) -- (py);
\draw[dashed,ds-1] (p1) -- ([xshift=15mm]p2 |- p1) coordinate(p1s) (p2) -- (p1s |- p2);
\draw[{Triangle[]}-{Triangle[]}] (p1s) -- (p1s |- p2)
node[midway,below,sloped]{improvement in compression ratio};
\draw[dashed,ds-1] (p1) -- +(0,-15mm) coordinate(p1b) (p2) -- (p1b -| p2);
\draw[{Triangle[]}-{Triangle[]}] (p1b) -- (p1b -| p2)
node[right]{improvement in air mass};
\end{tikzpicture}
\end{document}