-
Notifications
You must be signed in to change notification settings - Fork 0
update(heatmap-basic): bokeh — comprehensive quality review #4255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,122 +1,132 @@ | ||||||
| """ pyplots.ai | ||||||
| heatmap-basic: Basic Heatmap | ||||||
| Library: bokeh 3.8.1 | Python 3.13.11 | ||||||
| Quality: 92/100 | Created: 2025-12-23 | ||||||
| Library: bokeh 3.8.2 | Python 3.14.3 | ||||||
| Quality: 91/100 | Updated: 2026-02-15 | ||||||
| """ | ||||||
|
|
||||||
| import numpy as np | ||||||
| import pandas as pd | ||||||
| from bokeh.io import export_png, save | ||||||
| from bokeh.models import BasicTicker, ColorBar, ColumnDataSource, LabelSet, LinearColorMapper | ||||||
| from bokeh.palettes import Viridis256 | ||||||
| from bokeh.models import BasicTicker, ColumnDataSource, HoverTool, LabelSet | ||||||
| from bokeh.plotting import figure | ||||||
| from bokeh.resources import CDN | ||||||
| from bokeh.transform import linear_cmap | ||||||
|
|
||||||
|
|
||||||
| # Data - Monthly sales performance by product category | ||||||
| # Data - Monthly temperature anomalies (°C) by city | ||||||
| np.random.seed(42) | ||||||
| x_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug"] | ||||||
| y_labels = ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"] | ||||||
|
|
||||||
| # Generate heatmap values (sales performance 0-100) | ||||||
| values = np.random.rand(len(y_labels), len(x_labels)) * 100 | ||||||
|
|
||||||
| # Flatten data for ColumnDataSource | ||||||
| x_data = [] | ||||||
| y_data = [] | ||||||
| value_data = [] | ||||||
| text_data = [] | ||||||
| text_color_data = [] | ||||||
|
|
||||||
| for i, y in enumerate(y_labels): | ||||||
| for j, x in enumerate(x_labels): | ||||||
| x_data.append(x) | ||||||
| y_data.append(y) | ||||||
| months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct"] | ||||||
| cities = ["Oslo", "Berlin", "Madrid", "Cairo", "Mumbai", "Tokyo", "Sydney"] | ||||||
|
|
||||||
| # Generate realistic temperature anomalies with geographic patterns | ||||||
| base_anomalies = np.random.randn(len(cities), len(months)) * 0.6 | ||||||
| # Northern cities: colder winters, warmer summers | ||||||
| for i, city in enumerate(cities): | ||||||
| seasonal = np.sin(np.linspace(-np.pi / 2, 3 * np.pi / 4, len(months))) | ||||||
| if city in ("Oslo", "Berlin"): | ||||||
| base_anomalies[i] += seasonal * 1.5 - 0.3 | ||||||
| elif city in ("Madrid", "Cairo"): | ||||||
| base_anomalies[i] += seasonal * 1.2 + 0.4 | ||||||
| elif city == "Mumbai": | ||||||
| base_anomalies[i] += 0.8 | ||||||
| elif city == "Sydney": | ||||||
| base_anomalies[i] -= seasonal * 0.9 | ||||||
| elif city == "Tokyo": | ||||||
| base_anomalies[i] += seasonal * 0.7 | ||||||
|
|
||||||
| values = np.round(base_anomalies, 1) | ||||||
|
|
||||||
| # Flatten to DataFrame for ColumnDataSource | ||||||
|
||||||
| # Flatten to DataFrame for ColumnDataSource | |
| # Flatten data for ColumnDataSource |
Copilot
AI
Feb 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be simplified to source = ColumnDataSource(data=records) without wrapping records in pd.DataFrame. This makes the code simpler and removes the unnecessary pandas dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary pandas import. The ColumnDataSource can be created directly from a dictionary without using pandas. The old implementation used
ColumnDataSource(data={...})which is simpler and doesn't require pandas as a dependency. This violates the KISS principle for plot implementations which should be simple, readable scripts.