#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import pandas as pd from datetime import datetime from lets_plot import * # In[2]: LetsPlot.setup_html() # # Verifying hjust and vjust for axis labels # In[3]: data = { "x": ["OXXXXXXX", "OOOOO", "It's lXXX", "XOOOOXXX"], "y": [500, 1000, 500, 0], "z": ["a", "b", "c", "d"] } # In[4]: justifications = [1.0, 0.5, 0.0] angles=[90, 30, 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] def create_plot_grid(position): for angle in angles: print('-'*150) print(f'ANGLE: {angle}°') (gggrid(generate_all_plots(position, angle), ncol=3) + ggsize(1024, 1024)).show() # ## Default values # In[6]: ggplot(data) + \ geom_point(aes(x="x", y="y"), size=5) + \ theme_classic() + \ theme(axis_text_x=element_text(angle=30), axis_text_y=element_text(angle=30)) + \ ggsize(450, 312) # # Bottom axis # In[7]: create_plot_grid('bottom') # # Top axis # In[8]: create_plot_grid('top') # # Left axis # In[9]: create_plot_grid('left') # # Right axis # In[10]: create_plot_grid('right') # # Unusual values # In[11]: ggplot(data) + \ geom_point(aes(x="x", y="y"), size=5) + \ theme_classic() + \ theme(axis_text_x=element_text(angle=-30, hjust = 0.7, vjust=0.2), axis_text_y=element_text(angle=30, hjust=1, vjust=0.2)) + \ ggsize(450, 312) # In[ ]: