Changing the axes layouts¶
matplotlib
, by default, creates plots with the y-axis on the left side of the plot.
In plots of 2D spectra, it is often desirable to move the y-axis to the right.
It is possible to do this with a series of matplotlib
functions, but penguins
provides a built-in function for this purpose, ymove()
.
You can simply call this function on its own and it will move the axes labels to the very sensible top-right position.
Note that this function must be called after mkplot()
.
import numpy as np
import matplotlib.pyplot as plt
import penguins as pg
ds = pg.read(".", 2)
ds.stage(levels=5e5, f1_bounds="0.3..7", f2_bounds="0.3..7")
pg.mkplot()
pg.ymove()
pg.show()
More specifically, ymove()
allows you to choose between three available styles.
All of them move the y-axis to the right, but differ in where they place the y-axis label.
“topright”: Moves the label to the top-right and places it in a horizontal orientation. (This is the default shown above)
“midright”: Moves the label to the middle of the axis and places it sideways next to the tick labels.
“topspin”: Rotates tick labels as well as the axis label. This mimics the normal display in TopSpin.
These are more easily illustrated with a diagram rather than with text.
import numpy as np
import matplotlib.pyplot as plt
import penguins as pg
fig, axs = pg.subplots2d(2, 2)
ds = pg.read(".", 2)
styles = ["none", "topright", "midright", "topspin"]
# Stage and construct as usual
for ax, style in zip(axs.flat, styles):
ds.stage(ax, levels=5e5, f1_bounds="0.3..7", f2_bounds="0.3..7")
pg.mkplot(ax, title=style)
# Apply the styles.
for ax, style in zip(axs.flat[1:], styles[1:]):
pg.ymove(ax, style)
# This is not necessary in a real plot and is only included to make
# it clear which plot is which.
plt.subplots_adjust(hspace=0.3, wspace=0.3)
pg.show()
There is also an analogous function xmove()
, but it is not very fully developed at this point in time, and in general should not really be needed unless you have a particular “house style” to follow.