import numpy as np
import pandas as pd
from datetime import datetime
from lets_plot import *
LetsPlot.setup_html()
data = {
"x": ["OXXXXXXX", "OOOOO", "It's lXXX", "XOOOOXXX"],
"y": [500, 1000, 500, 0],
"z": ["a", "b", "c", "d"]
}
justifications = [1.0, 0.5, 0.0]
angles=[90, 30, 0, -30, 90]
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()
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)
create_plot_grid('bottom')
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 0°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: -30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
create_plot_grid('top')
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 0°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: -30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
create_plot_grid('left')
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 0°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: -30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
create_plot_grid('right')
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 0°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: -30°
------------------------------------------------------------------------------------------------------------------------------------------------------ ANGLE: 90°
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)