Skip to content

Commit e637eb9

Browse files
Merge remote-tracking branch 'origin/main'
2 parents a4ddea4 + 13cdc08 commit e637eb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+12432
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
""" pyplots.ai
2+
chessboard-basic: Chess Board Grid Visualization
3+
Library: bokeh 3.8.2 | Python 3.13.11
4+
Quality: 91/100 | Created: 2026-01-08
5+
"""
6+
7+
from bokeh.io import export_png, save
8+
from bokeh.models import ColumnDataSource
9+
from bokeh.plotting import figure
10+
from bokeh.resources import CDN
11+
12+
13+
# Data - 8x8 chess board squares
14+
columns = list("abcdefgh")
15+
rows = list("12345678")
16+
17+
# Create square data
18+
x_coords = []
19+
y_coords = []
20+
colors = []
21+
22+
# Light square color (cream) and dark square color (brown)
23+
light_color = "#F0D9B5"
24+
dark_color = "#B58863"
25+
26+
for row_idx, _row in enumerate(rows):
27+
for col_idx, _col in enumerate(columns):
28+
# Center of each square
29+
x_coords.append(col_idx + 0.5)
30+
y_coords.append(row_idx + 0.5)
31+
# Alternating colors: light square at h1 (row 0, col 7)
32+
# Pattern: (row_idx + col_idx) even = dark, odd = light
33+
if (row_idx + col_idx) % 2 == 0:
34+
colors.append(dark_color)
35+
else:
36+
colors.append(light_color)
37+
38+
source = ColumnDataSource(data={"x": x_coords, "y": y_coords, "color": colors})
39+
40+
# Create figure with 1:1 aspect ratio (square)
41+
p = figure(
42+
width=3600,
43+
height=3600,
44+
title="chessboard-basic · bokeh · pyplots.ai",
45+
x_range=(-0.1, 8.1),
46+
y_range=(-0.1, 8.1),
47+
tools="",
48+
toolbar_location=None,
49+
)
50+
51+
# Draw squares as rectangles
52+
p.rect(x="x", y="y", width=1, height=1, source=source, color="color", line_color="#333333", line_width=2)
53+
54+
# Style the figure
55+
p.title.text_font_size = "32pt"
56+
p.title.align = "center"
57+
58+
# Configure x-axis (columns a-h)
59+
p.xaxis.ticker = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]
60+
p.xaxis.major_label_overrides = {0.5: "a", 1.5: "b", 2.5: "c", 3.5: "d", 4.5: "e", 5.5: "f", 6.5: "g", 7.5: "h"}
61+
p.xaxis.major_label_text_font_size = "24pt"
62+
p.xaxis.axis_label = "Column"
63+
p.xaxis.axis_label_text_font_size = "22pt"
64+
65+
# Configure y-axis (rows 1-8)
66+
p.yaxis.ticker = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]
67+
p.yaxis.major_label_overrides = {0.5: "1", 1.5: "2", 2.5: "3", 3.5: "4", 4.5: "5", 5.5: "6", 6.5: "7", 7.5: "8"}
68+
p.yaxis.major_label_text_font_size = "24pt"
69+
p.yaxis.axis_label = "Row"
70+
p.yaxis.axis_label_text_font_size = "22pt"
71+
72+
# Remove grid lines (the squares themselves form the grid)
73+
p.xgrid.visible = False
74+
p.ygrid.visible = False
75+
76+
# Style axis lines
77+
p.outline_line_color = "#333333"
78+
p.outline_line_width = 3
79+
80+
# Background
81+
p.background_fill_color = "#FAFAFA"
82+
83+
# Save outputs
84+
export_png(p, filename="plot.png")
85+
save(p, filename="plot.html", resources=CDN, title="chessboard-basic · bokeh · pyplots.ai")
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
""" pyplots.ai
2+
chessboard-basic: Chess Board Grid Visualization
3+
Library: highcharts unknown | Python 3.13.11
4+
Quality: 93/100 | Created: 2026-01-08
5+
"""
6+
7+
import tempfile
8+
import time
9+
import urllib.request
10+
from pathlib import Path
11+
12+
from highcharts_core.chart import Chart
13+
from highcharts_core.options import HighchartsOptions
14+
from highcharts_core.options.series.heatmap import HeatmapSeries
15+
from selenium import webdriver
16+
from selenium.webdriver.chrome.options import Options
17+
18+
19+
# Data - 8x8 chessboard with alternating colors
20+
# Value 0 = light square, 1 = dark square
21+
# Chess convention: h1 (bottom-right from white's perspective) is light
22+
columns = ["a", "b", "c", "d", "e", "f", "g", "h"]
23+
rows = ["1", "2", "3", "4", "5", "6", "7", "8"]
24+
25+
# Generate board data: each point is [col_index, row_index, value]
26+
# Value 0 = light square, 1 = dark square
27+
# Chess convention: h1 (bottom-right) is light, a1 (bottom-left) is dark
28+
# col indices: a=0, b=1, ..., h=7
29+
# row indices: 1=0, 2=1, ..., 8=7
30+
# h1 = (col=7, row=0): 7+0=7 odd -> should be light (value=0)
31+
# a1 = (col=0, row=0): 0+0=0 even -> should be dark (value=1)
32+
board_data = []
33+
for row_idx in range(8):
34+
for col_idx in range(8):
35+
# (col + row) odd -> light square (0), even -> dark square (1)
36+
is_light = (col_idx + row_idx) % 2 == 1
37+
board_data.append([col_idx, row_idx, 0 if is_light else 1])
38+
39+
# Create chart
40+
chart = Chart(container="container")
41+
chart.options = HighchartsOptions()
42+
43+
# Chart configuration for square 1:1 aspect ratio
44+
chart.options.chart = {
45+
"type": "heatmap",
46+
"width": 3600,
47+
"height": 3600,
48+
"backgroundColor": "#ffffff",
49+
"marginTop": 120,
50+
"marginBottom": 200,
51+
"marginLeft": 150,
52+
"marginRight": 100,
53+
}
54+
55+
# Title
56+
chart.options.title = {
57+
"text": "chessboard-basic · highcharts · pyplots.ai",
58+
"style": {"fontSize": "48px", "fontWeight": "bold"},
59+
}
60+
61+
# X-axis (columns a-h)
62+
chart.options.x_axis = {
63+
"categories": columns,
64+
"title": {"text": None},
65+
"labels": {"style": {"fontSize": "36px", "fontWeight": "bold"}},
66+
"lineWidth": 2,
67+
"lineColor": "#333333",
68+
"tickLength": 0,
69+
"opposite": False,
70+
}
71+
72+
# Y-axis (rows 1-8)
73+
chart.options.y_axis = {
74+
"categories": rows,
75+
"title": {"text": None},
76+
"labels": {"style": {"fontSize": "36px", "fontWeight": "bold"}},
77+
"lineWidth": 2,
78+
"lineColor": "#333333",
79+
"tickLength": 0,
80+
"reversed": False,
81+
}
82+
83+
# Color axis for light/dark squares
84+
# Classic chess colors: cream (#F0D9B5) for light, brown (#B58863) for dark
85+
chart.options.color_axis = {"min": 0, "max": 1, "stops": [[0, "#F0D9B5"], [1, "#B58863"]], "visible": False}
86+
87+
# Disable legend
88+
chart.options.legend = {"enabled": False}
89+
90+
# Tooltip
91+
chart.options.tooltip = {
92+
"enabled": True,
93+
"formatter": """function() {
94+
var col = this.series.xAxis.categories[this.point.x];
95+
var row = this.series.yAxis.categories[this.point.y];
96+
return '<b>' + col + row + '</b>';
97+
}""",
98+
"style": {"fontSize": "24px"},
99+
}
100+
101+
# Plot options for heatmap
102+
chart.options.plot_options = {"heatmap": {"borderWidth": 2, "borderColor": "#333333", "dataLabels": {"enabled": False}}}
103+
104+
# Create and add series
105+
series = HeatmapSeries()
106+
series.data = board_data
107+
series.name = "Chess Board"
108+
109+
chart.add_series(series)
110+
111+
# Export to PNG via Selenium
112+
# Download Highcharts JS and heatmap module (required for headless Chrome)
113+
highcharts_url = "https://code.highcharts.com/highcharts.js"
114+
with urllib.request.urlopen(highcharts_url, timeout=30) as response:
115+
highcharts_js = response.read().decode("utf-8")
116+
117+
heatmap_url = "https://code.highcharts.com/modules/heatmap.js"
118+
with urllib.request.urlopen(heatmap_url, timeout=30) as response:
119+
heatmap_js = response.read().decode("utf-8")
120+
121+
# Generate HTML with inline scripts
122+
html_str = chart.to_js_literal()
123+
html_content = f"""<!DOCTYPE html>
124+
<html>
125+
<head>
126+
<meta charset="utf-8">
127+
<script>{highcharts_js}</script>
128+
<script>{heatmap_js}</script>
129+
</head>
130+
<body style="margin:0;">
131+
<div id="container" style="width: 3600px; height: 3600px;"></div>
132+
<script>{html_str}</script>
133+
</body>
134+
</html>"""
135+
136+
# Write temp HTML and take screenshot
137+
with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False, encoding="utf-8") as f:
138+
f.write(html_content)
139+
temp_path = f.name
140+
141+
# Also save HTML for interactive version
142+
with open("plot.html", "w", encoding="utf-8") as f:
143+
f.write(html_content)
144+
145+
chrome_options = Options()
146+
chrome_options.add_argument("--headless")
147+
chrome_options.add_argument("--no-sandbox")
148+
chrome_options.add_argument("--disable-dev-shm-usage")
149+
chrome_options.add_argument("--disable-gpu")
150+
chrome_options.add_argument("--window-size=3600,3600")
151+
152+
driver = webdriver.Chrome(options=chrome_options)
153+
driver.get(f"file://{temp_path}")
154+
time.sleep(5)
155+
driver.save_screenshot("plot.png")
156+
driver.quit()
157+
158+
Path(temp_path).unlink()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
""" pyplots.ai
2+
chessboard-basic: Chess Board Grid Visualization
3+
Library: letsplot 4.8.2 | Python 3.13.11
4+
Quality: 95/100 | Created: 2026-01-08
5+
"""
6+
7+
import os
8+
import shutil
9+
10+
import pandas as pd
11+
from lets_plot import (
12+
LetsPlot,
13+
aes,
14+
coord_fixed,
15+
element_blank,
16+
element_text,
17+
geom_tile,
18+
ggplot,
19+
ggsave,
20+
ggsize,
21+
labs,
22+
scale_fill_manual,
23+
scale_x_discrete,
24+
scale_y_discrete,
25+
theme,
26+
)
27+
28+
29+
LetsPlot.setup_html()
30+
31+
# Data - create 8x8 chess board grid
32+
columns = list("abcdefgh")
33+
rows = list(range(1, 9))
34+
35+
# Build data for all 64 squares
36+
data = []
37+
for col_idx, col in enumerate(columns):
38+
for row_idx, row in enumerate(rows):
39+
# Light square at h1 (col_idx=7, row_idx=0) means (col_idx + row_idx) % 2 == 1 is light
40+
is_light = (col_idx + row_idx) % 2 == 1
41+
data.append({"column": col, "row": str(row), "color": "light" if is_light else "dark"})
42+
43+
df = pd.DataFrame(data)
44+
45+
# Create the chess board visualization
46+
plot = (
47+
ggplot(df, aes(x="column", y="row", fill="color"))
48+
+ geom_tile(color="#5D4037", size=0.5) # Brown borders for definition
49+
+ scale_fill_manual(values={"light": "#F5DEB3", "dark": "#8B4513"}) # Cream and brown
50+
+ scale_x_discrete(limits=columns)
51+
+ scale_y_discrete(limits=[str(r) for r in rows])
52+
+ coord_fixed(ratio=1) # 1:1 aspect ratio for square cells
53+
+ labs(title="chessboard-basic · letsplot · pyplots.ai")
54+
+ theme(
55+
plot_title=element_text(size=24, face="bold"),
56+
axis_title=element_blank(),
57+
axis_text_x=element_text(size=20, face="bold"),
58+
axis_text_y=element_text(size=20, face="bold"),
59+
legend_position="none",
60+
panel_grid=element_blank(),
61+
panel_background=element_blank(),
62+
plot_background=element_blank(),
63+
)
64+
+ ggsize(1200, 1200) # Square canvas, scaled 3x = 3600x3600 px
65+
)
66+
67+
# Save as PNG (scale 3x for 3600x3600 px output)
68+
ggsave(plot, "plot.png", scale=3)
69+
70+
# Save interactive HTML version
71+
ggsave(plot, "plot.html")
72+
73+
# lets-plot saves to a subdirectory by default - move files to current directory
74+
if os.path.exists("lets-plot-images/plot.png"):
75+
shutil.move("lets-plot-images/plot.png", "plot.png")
76+
if os.path.exists("lets-plot-images/plot.html"):
77+
shutil.move("lets-plot-images/plot.html", "plot.html")
78+
if os.path.exists("lets-plot-images") and not os.listdir("lets-plot-images"):
79+
os.rmdir("lets-plot-images")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
""" pyplots.ai
2+
chessboard-basic: Chess Board Grid Visualization
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 95/100 | Created: 2026-01-08
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
9+
10+
# Board configuration
11+
rows = 8
12+
cols = 8
13+
column_labels = ["a", "b", "c", "d", "e", "f", "g", "h"]
14+
row_labels = ["1", "2", "3", "4", "5", "6", "7", "8"]
15+
16+
# Classic chess colors (cream and brown)
17+
light_color = "#F0D9B5"
18+
dark_color = "#B58863"
19+
20+
# Create figure (square aspect ratio for chess board)
21+
fig, ax = plt.subplots(figsize=(12, 12))
22+
23+
# Draw the chess board squares
24+
for row in range(rows):
25+
for col in range(cols):
26+
# h1 (col=7, row=0) should be light, so (row + col) even = light
27+
color = light_color if (row + col) % 2 == 1 else dark_color
28+
rect = plt.Rectangle((col, row), 1, 1, facecolor=color, edgecolor="#5D4037", linewidth=1)
29+
ax.add_patch(rect)
30+
31+
# Set axis limits
32+
ax.set_xlim(0, 8)
33+
ax.set_ylim(0, 8)
34+
35+
# Set column labels (a-h) at the bottom
36+
ax.set_xticks([i + 0.5 for i in range(8)])
37+
ax.set_xticklabels(column_labels, fontsize=20, fontweight="bold")
38+
39+
# Set row labels (1-8) on the left side
40+
ax.set_yticks([i + 0.5 for i in range(8)])
41+
ax.set_yticklabels(row_labels, fontsize=20, fontweight="bold")
42+
43+
# Style the axis
44+
ax.tick_params(axis="both", length=0, pad=10)
45+
ax.set_aspect("equal")
46+
47+
# Remove spines and add a border
48+
for spine in ax.spines.values():
49+
spine.set_visible(True)
50+
spine.set_linewidth(3)
51+
spine.set_color("#5D4037")
52+
53+
# Title
54+
ax.set_title("chessboard-basic · matplotlib · pyplots.ai", fontsize=24, fontweight="bold", pad=20)
55+
56+
plt.tight_layout()
57+
plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor="white")

0 commit comments

Comments
 (0)