In [1]:
import numpy as np
import pandas as pd
from datetime import datetime
from lets_plot import *
In [2]:
LetsPlot.setup_html()

Multiline axis labels

In [3]:
data = {
    "x": ["Single", "2\nlines", "Multiline\nlabel", "Label\n#4\n(of 4)"],
    "y": [500, 1000, 500, 0],
    "z": ["a", "b", "c", "d"]
}
In [4]:
justifications = [1.0, 0.5, 0.0]
angles=[0, 30, 90]
In [5]:
def create_plot(position, angle, hjust, vjust):
    if position == 'top' or position == 'bottom':
        theme_element = theme(axis_text_x=element_text(angle=angle, hjust=hjust, vjust=vjust), axis_title="blank") + \
            scale_x_discrete(position = f'{position}')
        x_data = "x"
    else:
        theme_element = theme(axis_text_y=element_text(angle=angle, hjust=hjust, vjust=vjust), axis_title="blank") + \
            scale_y_discrete(position = f'{position}') 
        x_data = "z"
    return (
        ggplot(data) + 
        geom_point(aes(x=x_data, y="y"), size=5) + 
        theme_classic() + 
        ggtitle(f"h{hjust}, v{vjust}") +
        theme_element
    )

        
def generate_all_plots(position, angle):
    return [create_plot(position=position, angle=angle, hjust=hjust, vjust=vjust)
        for hjust in justifications
        for vjust in justifications]
In [6]:
gggrid(generate_all_plots('bottom', 0), ncol=3) 
Out[6]:
In [7]:
gggrid(generate_all_plots('bottom', 30), ncol=3) 
Out[7]:
In [8]:
gggrid(generate_all_plots('bottom', 90), ncol=3) 
Out[8]:
In [ ]: