以數學公式作為x軸標籤繪製長條圖

以數學公式作為x軸標籤繪製長條圖

我正在嘗試製作一個與下圖類似的條形圖,但遇到了麻煩,因為我找不到一種方法來製作沒有錯誤的 x 軸標籤,因為它們由等表示$\ket{000}$

在此輸入影像描述

以下是我想做的工作

    \begin{tikzpicture}
\begin{axis}[
    x tick label style={
        /pgf/number format/1000 sep=},
    ylabel=Year,
    enlargelimits=0.05,
    legend style={at={(0.5,-0.1)},
    anchor=north,legend columns=-1},
    ybar interval=0.7,
]
\addplot 
    coordinates {($\ket{000}$,4) ($\ket{001}$,4)
         ($\ket{010}$,7) ($\ket{011}$,-5) ($\ket{100}$,3)};
\end{axis}
\end{tikzpicture}

答案1

像這樣的東西嗎?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{braket}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            x tick label style={/pgf/number format/1000 sep=},
            ylabel=Year,
            enlargelimits=0.05,
            legend style={at={(0.5,-0.1)},anchor=north,legend columns=-1},
            ybar interval=0.7,
            symbolic x coords = {$\ket{000}$, $\ket{001}$, $\ket{010}$, $\ket{011}$, $\ket{100}$, 6}
        ]
        \addplot 
        coordinates {($\ket{000}$,4) ($\ket{001}$,4) ($\ket{010}$,7) ($\ket{011}$,-5) ($\ket{100}$,3) (6,3)};
        \end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容