我正在尝试创建这个:
我已经能够创建不规则形状,即使它不相似,问题是如何在特定刻度处添加 x 刻度和 y 刻度,例如 K、d、y、a、x、b?不是通常的 0、1、2、3。
这是我的 MWE:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{axis line style/.style={thin, gray, -stealth}}
\begin{document}
\begin{tikzpicture}[scale=1,>=latex,x=1cm,y=0.8cm]
\draw plot[domain=0:350, smooth cycle] (\x:2+rnd*0.7);
% x axis and y axis with ticks
\draw [axis line style] (-4.5,-4) -- (5.5,-4);% x-axis
\draw [axis line style] (-3,-4.5) -- (-3,5.5);% y-axis
\end{tikzpicture}
\end{document}
答案1
作为起点:
\documentclass[12pt, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
decorations.pathreplacing,%
calligraphy,% had to be after
intersections}
\begin{document}
\begin{tikzpicture}[
scale=2,
>=latex,
arr/.style = {-{Straight Barb[scale=2]}, semithick},
BC/.style args = {#1/#2}{
decorate,
decoration={calligraphic brace, amplitude=6pt,
pre =moveto, pre length=1pt,
post=moveto, post length=1pt,
raise=#1},
ultra thick,
pen colour={#2}
},
lbl/.style = {font=\Large}
]
% axis
\draw [arr] (-3,-3) coordinate (aux)
-- ++ (7,0) node[below left=1mm] {$x$};% x-axis
\draw [arr] (-3,-3) -- ++ (0,7) node[below left=1mm] {$x$};% y-axis
% iregular shape
\pgfmathsetseed{8}
\path[draw=blue!50, ultra thick, fill= blue!50, fill opacity=0.5,
name path=A]
plot[domain=0:350, smooth cycle] (\x:2+rnd*0.8);
% intersections
\path[name path=X] (-1,-4) -- ++ (0,7);
\path[name path=Y] (-4,1) -- ++ (7,0);
\draw [name intersections={of=A and X, by={x1, x2}},
draw=blue, thick] (x1) -- (x2);
\draw [name intersections={of=A and Y, by={y1, y2}},
draw=blue, thick] (y1) -- (y2);
% braces
\draw[BC=3pt/red] (x1) -- node[lbl, right=5pt] {$h(x)$} (x2);
\draw[BC=3pt/red] (y1) -- node[lbl, below=5pt] {$w(y)$} (y2);
% ticks
\draw (x1 |- aux) ++ (0,0.1)-- ++ (0,-0.2) node[below] {$x$}
(y1 -| aux) ++ (0.1,0)-- ++ (-0.2,0) node[left] {$y$}
(-2.62,-2.9) -- ++ (0,-0.2) node[below] {$a$}
( 2.75,-2.9) -- ++ (0,-0.2) node[below] {$b$}
(-2.9,-2.62) -- ++ (-0.2,0) node[left] {$c$}
(-2.9,+2.75) -- ++ (-0.2,0) node[left] {$d$}
;
% grid, for finding min and max shape values
% after their finding, you can delete both grids
\scoped[on background layer]
{
\draw[gray!30] (-3,-3) grid[step= 2mm] (3,3);
\draw[gray] (-3,-3) grid[step=10mm] (3,3);
}
\foreach \i in {-2,...,2}
{
\node[above, fill=white, font=\scriptsize] at (\i,-3) {$\i$};
\node[right, fill=white, font=\scriptsize] at (-3,\i) {$\i$};
}
\end{tikzpicture}
\end{document}
笔记:在实际文档中删除注释后的代码
% grid, for finding min and max shape values,
% after their finding, you can delete both grids