我整天阅读pgfplots
手册,但不幸的是我无法实现以下目标:
(1)legend style
:使图例方程左对齐,并将矩形框修改为其他形状(或最好:删除矩形框)
(2)添加简单的虚线,我试图绘制路径,但它们并没有出现在我想要的位置:/例如从到x=7
两条曲线的交点。
\documentclass[13pt,a4paper,headlines=6,headinclude=true]{scrartcl}
\usepackage{tikz,pgfplots}
\usepackage{amsmath,amssymb,stmaryrd}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[axis lines=middle,xmin=-5,xmax=16,ymin=2,ymax=299,
extra x ticks={0,4,7},
tick label style={font=\tiny},
legend style={font=\tiny,legend pos=outer north east}
]
\addplot+[no marks,blue,domain=0.2:10,samples=150, thick] {(x)^3 - 12*(x)^2 + 60*x+98};
\addlegendentry{$C(x) = x^3 - 12x^2 + 60x+98$};
\addplot+[no marks,red,domain=0.2:13,samples=150, thick] {3*(x)^2 - 24*x + 60};
\addlegendentry{$MC(x)=3x^2 - 24x + 60$};
\addplot+[no marks,orange,domain=0.2:13,samples=150, thick] {(x)^2 - 12*x + 60 + (98)/(x)};
\addlegendentry{$AV(x)=x^2 - 12x + 60 + \frac{98}{x}$};
\path[draw=gray, dashed] (4,2) -- (4,50);
\path[draw=gray, dashed] (10,-2) -- (10,50);
\end{axis}
\end{tikzpicture}
\end{document}
如果您能提供进一步的意见,让这个看起来更美观,我将非常感激。非常感谢。
答案1
要移除方框,请使用draw=none
;要将方程式向左对齐,请cells={anchor=west}
使用
legend style={draw=none,font=\tiny,legend pos=outer north east,cells={anchor=west}}
此外,您需要添加`\pgfplotsset{compat=1.12}才能使用
\path[draw=gray, dashed] (10,-2) -- (10,50);
否则,你可能必须使用
\path[draw=gray, dashed] (axis cs:10,-2) -- (axis cs:10,50);
代码:
\documentclass[13pt,a4paper,headlines=6,headinclude=true]{scrartcl}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[axis lines=middle,xmin=-5,xmax=16,ymin=2,ymax=299,
extra x ticks={0,4,7},
tick label style={font=\tiny},
legend style={draw=none,font=\tiny,legend pos=outer north east,cells={anchor=west}}
]
\addplot+[no marks,blue,domain=0.2:10,samples=150, thick] {(x)^3 - 12*(x)^2 + 60*x+98};
\addlegendentry{$C(x) = x^3 - 12x^2 + 60x+98$};
\addplot+[no marks,red,domain=0.2:13,samples=150, thick] {3*(x)^2 - 24*x + 60};
\addlegendentry{$MC(x)=3x^2 - 24x + 60$};
\addplot+[no marks,orange,domain=0.2:13,samples=150, thick] {(x)^2 - 12*x + 60 + (98)/(x)};
\addlegendentry{$AV(x)=x^2 - 12x + 60 + \frac{98}{x}$};
\path[draw=gray, dashed] (4,2) -- (4,50);
\path[draw=gray, dashed] (10,-2) -- (10,50);
\end{axis}
\end{tikzpicture}
\end{document}
要改变形状,请使用usetikzlibrary{shapes.geometric}
(例如)然后
legend style={ellipse,fill=olive,font=\tiny,legend pos=outer north east,cells={anchor=west}}
给出(丑陋)
和
legend style={rounded corners,fill=olive!40,font=\tiny,legend pos=outer north east,cells={anchor=west}}
我们得到