如何旋转 pgfplot?

如何旋转 pgfplot?

我正在尝试创建这样的情节:

B类放大器
(来源:uson.mx

到目前为止,我到达了这里:

乳胶载重线

使用以下(最小化)代码:

\documentclass{report}
\usepackage{pgfplots}   
\pgfplotsset{compat=1.8}

\begin{document}        
    \begin{tikzpicture}
    
        \begin{axis}[
                cycle list name=color list,
                axis x line=bottom,
                axis y line=left,
            ]
        
            \foreach \i in {1,2,3,4,5,6} {
                \addplot+[black] coordinates{
                    (0,0)
                    (sqrt(\i/1.5),\i)
                    (11,\i)};   
            }                   
            
            \addplot+[red] coordinates{(2,6)(10,0)};    
                
            \end{axis}  
                                
                \begin{axis}[
                cycle list name=color list,  
                axis x line=bottom,
                axis y line=left,
                    xmin=-5,    xmax=10
                    %axis lines=none
            ]       
                
                \pgftransformshift{-100}
                
                \addplot+[green,domain=-5:0] {sin(x*90)+3}; 
        
            \end{axis}  
                                
                \begin{axis}[
                cycle list name=color list,  
                axis x line=bottom,
                axis y line=left,
                    xmin=-5,    xmax=10,
                    axis lines=none
            ]       
                
                \pgftransformrotate{30}
                
                \addplot+[green,domain=5:10] {sin(x/2*90)+2};   
        
            \end{axis}      
                        
                            
                \begin{axis}[
                cycle list name=color list,  
                axis x line=bottom,
                axis y line=left,
                    xmin=-2,    xmax=10,
                    ymin=0, ymax=10
                    %axis lines=none
            ]       
                
                \pgftransformrotate{270}
                
                \addplot+[green,domain=0:3] {-sin(x/3*180)*8+10};   
        
            \end{axis}          

    \end{tikzpicture}
\end{document}

因此,我的主要问题是正弦波的旋转和对齐。我不确定我尝试的方法是否可行,因为我看不到将四个不同的轴精确对齐的可能性,任何提示都值得感激。

编辑1:

这是我的底层图,我怎样才能将正弦图的中心移到红点之上?我会提供代码,但它相当长。

B类放大器

编辑2:

好的,明白了。有些东西可能看起来不太优雅,但也许这对某些人有用:

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{pgfplots}   
\pgfplotsset{compat=1.8}
\usepackage{pgfplotstable}  
\usetikzlibrary{patterns}
\usetikzlibrary{calc}

\begin{document}

    \centering
    \begin{tikzpicture}
    [/pgfplots/y=8cm, /pgfplots/x=1cm] % To make sure all the plots use the same scale]
        
                
        %%  
        %% VOLTAGE INPUT
        %%      
        \begin{axis}[
            anchor=origin, % Shift the axis so its origin is at (0,0)   
            rotate around={63.5:(current axis.origin)}, % Rotate around the origin
            xmin=0, ymin=0, clip=false, % We only want the positive y axis, hence `ymin=0`. `clip=false` is necessary so we can still see the negative component
            xmax=4.5, ymax=0.8,
            axis lines*=center, % Axis lines going through the origin
            xtick=\empty, ytick=\empty, % No tick marks
            enlarge y limits={upper, value=0.5}, % Make the y axis a bit longer than necessary          
            axis y line=none
            ]           
            \addplot [thick, blue, domain=1:4, smooth] {0.895*sin(x*120-120)} coordinate [pos=0.25] (input); 
            \coordinate (aux) at (axis cs:0,0.895); % Name the coordinate on the axis for drawing the dashed lines later        
        \end{axis}
            
        %%  
        %% VOLTAGE OUTPUT
        %%          
        \begin{axis}[
            anchor=origin, % Same as before
            rotate around={-90:(current axis.origin)},
            axis lines*=center,
            xtick=\empty, ytick=\empty,
            xmin=0, ymin=0, clip=false, % We only want the positive y axis, hence `ymin=0`. `clip=false` is necessary so we can still see the negative component
            xmax=5.25, ymax=0.8,
            hide y axis % The y axis coincides with the x axis of the previous axis, so we hide it to avoid drawing it twice
            ]
            \addplot [line join=round,thick, red, domain=2:3.62, smooth] {-0.80*sin(x*120-240)} coordinate [pos=0.45] (output); % half a sine wave
            \addplot [line join=round,thick, red, domain=3.61:4.89, smooth]   {0.2} coordinate [pos=0] (rail_volt); 
            \addplot [line join=round,thick, red, domain=4.88:5, smooth] {-0.80*sin(x*120-240)}; % half a sine wave                                 
        \end{axis}      

        %%  
        %% CURRENT
        %%
        \begin{axis}[
                anchor=origin,
                axis lines*=center,
                xtick=\empty, ytick=\empty,
                hide y axis,
                hide x axis,
                xmin=-12.25, ymin=0, clip=false, % We only want the positive y axis, hence `ymin=0`. `clip=false` is necessary so we can still see the negative component
                xmax=0, ymax=0.8,               
                enlarge x limits={upper, value=1} % Extend the axis to the right
                ]   
            \addplot [smooth,thick, black, domain=-12.5:-12.38] {0.4*sin(x*120+4560)}; % Shifted half sine wave
            \addplot [smooth,thick, black, domain=-12.39:-11.11] {-0.1} coordinate [pos=0] (rail_curr); % Shifted half sine wave        
            \addplot [smooth,thick, black, domain=-11.12:-9.5] {0.4*sin(x*120+4560)} coordinate [pos=0.545] (current); % Shifted half sine wave 
            \addplot [smooth,thin,  black, domain=-12.75:-9.2] {0};             
        \end{axis}
        
    
            
        \begin{axis}[
                anchor=origin,
                at={(-84,-10)}, 
                cycle list name=color list,  %% AXIS FORMAT
                axis x line=bottom,
                axis y line=left,
                xlabel style={at={(current axis.right of origin)},align=center,yshift=-0.5em, xshift=-3em,  anchor=north west},
                ylabel style={at={(current axis.above origin)},align=center,yshift=0em, xshift=+2.5em, anchor=north east,rotate=270},
                xlabel={$V_{DS},\;\lbrack V\rbrack$},
                ylabel={$I_{DS},$\\$\lbrack A\rbrack$},
                xtick={0,2,...,10},                                                     % {0,2,...,10} (the same as {0,2,4,6,8,10}), {0,1,2,5,8,1e1,1.5e1} (a series of coordinates)
                minor xtick={0,1,...,11},       
                %%extra x ticks={22},
                ytick={0,0.1,...,0.6},
                minor ytick={0,0.05,...,0.55},
                xmin=0, xmax=12,
                ymin=0, ymax=0.55,
                %x=1cm, y=1cm,
                %legend pos=south east,
                %grid=major,                                                % /pgfplots/grid=minor|major|both|none 
                height=5cm,
                width=10cm,
                axis on top,
                yticklabel style={draw=none, inner sep=0pt, outer sep=0.3333em, fill=white, text opacity=1},
                xticklabel style={draw=none, inner sep=0pt, outer sep=0.3333em, fill=white, text opacity=1}
            ]
            \pgfplotstablenew[
                create on use/x/.style={create col/expr={0+\pgfplotstablerow*0.05}},
                create on use/y/.style={create col/expr={\thisrow{x}*0+0.65}},
                columns={x,y}]
                {43}
                \ftable
            \pgfplotstablenew[
                create on use/x/.style={create col/expr={0+\pgfplotstablerow*0.05}},
                create on use/y/.style={create col/expr={0.125*(\thisrow{x})^2}},
                columns={x,y}]
                {43}
                \gtable
            % Sort the second table by the x value, from largest to smallest
            \pgfplotstablesort[sort cmp={float >}]\gsorted{\gtable}
            %\pgfplotstabletypeset\gsorted
            % Concatenate the tables -- now filledcurve contains the edge of
            % a polygon bounded by curves f and g
            \pgfplotstablevertcat{\filledcurve}{\ftable}
            \pgfplotstablevertcat{\filledcurve}{\gsorted}
            
            \addplot+[opacity=0.8,fill opacity=0.3,draw=none,fill=yellow,postaction={pattern=north east lines}] coordinates {(11,0.55) (12,0.55) (12,0) (11,0)};            
            \addplot[fill=gray,opacity=0.7,fill opacity=0.2,draw=none,postaction={pattern=north east lines}] table {\filledcurve};  
            \foreach \i in {0.1,0.2,0.3,0.4,0.5} {
                \addplot+[black] coordinates{
                    (0,0)
                    (sqrt(\i/0.125),\i)
                    (11,\i)};   
                \addplot+[black,domain=11:12] {((x-11)^4*5)+\i};    
            }   
            
            \addplot+[gray,domain=0:2.2] {0.125*x^2};           
            \coordinate (rail_abs) at (axis cs:10,0); % Name the coordinate on the axis for drawing the dashed lines later                  
            \addplot+[ultra thick, red] coordinates{(2,0.5)(10,0)}; 
            %%\node[red] at (axis cs:8.4,0.1) {\textbullet}; %(8.6666666666666666666)       
            \draw[thick, black, fill=red] (axis cs:8.4,0.1) circle(1mm);    
            \end{axis}
                        

            \draw [densely dashed] (input) -- (aux); % Draw the dashed line
            
            \draw [densely dashed] (output) -- ($(aux)-(0,4.6)$); % Draw the dashed line            
            \draw [densely dashed] (aux) -- ($(aux)-(0,4.0)$); % Draw the dashed line
            
            \draw [densely dashed] ($(rail_abs)-(0,0.6)$) -- (rail_volt); % Draw the dashed line
                            
                            
            \draw [densely dashed] (current) -- ($(aux)-(2.8,0)$); % Draw the dashed line       
            \draw [densely dashed] ($(aux)-(2,0)$) -- (aux); % Draw the dashed line     
                                                                    
            \draw [densely dashed] (rail_curr) -- ($(rail_abs)-(10.6,0)$); % Draw the dashed line       
                        


    \end{tikzpicture}
\end{document}

完成图

答案1

您可以通过设置精确定位和旋转轴anchor=origin, rotate around={<angle>:(current axis.origin)}

\documentclass{report}
\usepackage{pgfplots}   
\pgfplotsset{compat=1.8}

\begin{document}        
\begin{tikzpicture}[
    /pgfplots/y=2cm, /pgfplots/x=0.1mm % To make sure all the plots use the same scale
]
\begin{axis}[
    anchor=origin, % Shift the axis so its origin is at (0,0)
    rotate around={45:(current axis.origin)}, % Rotate around the origin
    xmin=0, ymin=0, clip=false, % We only want the positive y axis, hence `ymin=0`. `clip=false` is necessary so we can still see the negative component
    axis lines*=center, % Axis lines going through the origin
    xtick=\empty, ytick=\empty, % No tick marks
    enlarge y limits={upper, value=0.5} % Make the y axis a bit longer than necessary
]
\addplot [thick, blue, domain=60:420, smooth] {sin(x-60)*sqrt(2)} coordinate [pos=0.25] (input); % Add the plot, a sine wave shifted by 60 degrees and scaled by sqrt(2). Also add a node so we can draw the dashed lines later
\coordinate (aux) at (axis cs:0,{sqrt(2)}); % Name the coordinate on the axis for drawing the dashed lines later
\end{axis}

\begin{axis}[
    anchor=origin, % Same as before
    rotate around={-90:(current axis.origin)},
    axis lines*=center,
    xtick=\empty, ytick=\empty,
    xmin=0,
    hide y axis % The y axis coincides with the x axis of the previous axis, so we hide it to avoid drawing it twice
]
\addplot [thick, red, domain=180:360] {sin(x)} coordinate [pos=0.5] (output); % half a sine wave
\end{axis}

\begin{axis}[
    anchor=origin,
    axis lines*=center,
    xtick=\empty, ytick=\empty,
    xmax = 0, % We'll draw this in the negative domain, but need to make sure the origin is still included in the axis
    hide y axis, 
    enlarge x limits={upper, value=1} % Extend the axis to the right
]
\addplot [thick, black, domain=-420:-240] {sin(x+60)} coordinate [pos=0.5] (current); % Shifted half sine wave
\end{axis}

\draw [densely dashed] (input) -- (aux) -- (output) (aux) -- (current); % Draw the dashed line
\end{tikzpicture}
\end{document}

相关内容