# Codebook: From a Different Angle

Ask here about the “From a Different Angle” Codebook topic from the “Single-Qubit Gates” module.

I tried to replicate the code in my own notebook. I cannot find a source for the plotter() function. Is it from specific libraries like Plotly or matplotlib? Or is it a custom-defined function?

Hi @lawun330 , welcome to the Forum!

That’s an internal function that we had in this section of the Codebook. Here’s the code! Let me know if you have any issues with it.

``````def plotter(angles, amplitudes):
"""Plot the value of the output

Args:
angles (np.array[float]): Angles for the x axis.
amplitudes (np.array[complex]): State after applying RX(theta)
"""

df = pd.DataFrame(
{
"theta": angles,
"|0> real": amplitudes[:, 0].real,
"|0> imag": amplitudes[:, 0].imag,
"|1> real": amplitudes[:, 1].real,
"|1> imag": amplitudes[:, 1].imag,
}
)

plot_1 = (
alt.Chart(df)
.transform_fold(["|0> real", "|1> real"], ["quantity", "amplitude"])
.mark_line()
.encode(x="theta:Q", y="amplitude:Q", color="quantity:N")
)

plot_2 = (
alt.Chart(df)
.transform_fold(["|0> imag", "|1> imag"], ["quantity", "amplitude"])
.mark_line()
.encode(x="theta:Q", y="amplitude:Q", color="quantity:N")
)

return plot_1 + plot_2
``````
1 Like