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.
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
LetsPlot.set_theme(theme_grey())
df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')
df.head(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#
p = (ggplot(df) + geom_point(aes("sepal_width", "sepal_length", color="species"), size=5)
+ scale_color_brewer(palette="Set1")
)
p
2. position="right"#
p + scale_y_continuous("Sepal Length", position="right")
3. position="top"#
p + scale_x_continuous(position="top")
4. position="both"#
(p
+ scale_x_continuous("Sepal Width", position="both")
+ scale_y_continuous("Sepal Length", position="both")
)
4.1 Lets use equal units on the X-axis and on the Y-axis.#
(p
+ scale_x_continuous("Sepal Width", position="both")
+ scale_y_continuous("Sepal Length", position="both")
+ coord_fixed()
)