在 pgfplots 中旋转特定图

在 pgfplots 中旋转特定图

我对绘制这个图表很感兴趣。

Desired output

这就是我迄今为止所做的。

My output

代码:

\documentclass[a4paper]{article}

\usepackage[margin=0.8in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{physics}
\usepackage{circuitikz}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{tkz-fct}  
\usetikzlibrary{datavisualization}

\begin{document}
\begin{figure}[h!]
    \centering
    \begin{tikzpicture}
    \begin{axis} [
    no markers,
    axis lines = middle,
    axis line style = {->},
    xlabel = {$y_1$},
    ylabel = {$y_2$},
    xticklabels={,,}
    yticklabels={,,}
    ]          
    \addplot [mark=none, blue]{3*x};
    \addplot [mark=none, blue]{-3*x};
    \node[label={45:{$P_0(0,0)$}},circle,fill,inner sep=1pt] at (axis cs:0,0) {};
    \addplot[domain=-4:4, color=red,samples=2000] {x^2};  %statement 1
    \addplot[domain=-4:4, color=red,samples=2000] {-x^2}; %statement 2
     \end{axis}
    \end{tikzpicture}
    \end{figure}

\end{document}

现在我需要旋转代码中标记为语句 1 和语句 2 的图。

我曾尝试使用

\addplot[domain=-10:10, color=blue,samples=2000,
     transform canvas={rotate around={90:(0,0)}}]{x^2};

但我得到了一些荒谬的输出。我对 LaTeX 数学很有经验,但我对 TikZ 和 PGF 还不熟悉。

答案1

您仍然可以使用rotate around

\documentclass[border = 5pt]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis} [
  no markers,
  axis lines = middle,
  axis line style = {->},
  xlabel = {$y_1$},
  ylabel = {$y_2$},
  xticklabels={,,}
  yticklabels={,,},
  % added this
  anchor=origin,
  ]          
  \addplot [mark=none, blue]{3*x};
  \addplot [mark=none, blue]{-3*x};
  \node[label={45:{$P_0(0,0)$}},circle,fill,inner sep=1pt] at (axis cs:0,0) {};
  \end{axis}

  \begin{axis} [ % added this
    rotate around={-45:(current axis.origin)},
    anchor=origin,
    hide axis,
    ]
    \addplot[domain=-4:4, color=red,samples=200] {x^2};  %statement 1
    \addplot[domain=-4:4, color=red,samples=200] {-x^2}; %statement 2  
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

相关内容