Axis Position

The position parameter in scale_x_(), scale_y_() functions controls position of the axis:

  • 'left', 'right' or 'both' for y-axis;
  • 'top', 'bottom' or 'both' for x-axis.
In [1]:
import pandas as pd

from lets_plot import *
In [2]:
LetsPlot.setup_html()
LetsPlot.set_theme(theme_grey())
In [3]:
df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')
df.head(3)
Out[3]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa

1. Default Axis Position

In [4]:
p = (ggplot(df) + geom_point(aes("sepal_width", "sepal_length", color="species"), size=5)
      + scale_color_brewer(palette="Set1")
    )
p
Out[4]:

2. position="right"

In [5]:
p + scale_y_continuous("Sepal Length", position="right")
Out[5]:

3. position="top"

In [6]:
p + scale_x_continuous(position="top")
Out[6]:

4. position="both"

In [7]:
(p
 + scale_x_continuous("Sepal Width", position="both")
 + scale_y_continuous("Sepal Length", position="both")
)
Out[7]:
4.1 Lets use equal units on the X-axis and on the Y-axis.
In [8]:
(p
 + scale_x_continuous("Sepal Width", position="both")
 + scale_y_continuous("Sepal Length", position="both")
 + coord_fixed()
)
Out[8]: