-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add histogram-basic implementation (9 libraries) #512
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1c5cd18
feat(seaborn): implement histogram-basic (#285)
claude[bot] ff6261d
feat(matplotlib): implement histogram-basic (#281)
claude[bot] 97d7448
feat(altair): implement histogram-basic (#289)
claude[bot] 524deb4
feat(letsplot): implement histogram-basic (#303)
claude[bot] 6f676f1
feat(plotly): implement histogram-basic (#306)
claude[bot] e0345e7
feat(pygal): implement histogram-basic (#286)
claude[bot] 8649b78
feat(plotnine): implement histogram-basic (#284)
claude[bot] e7848d2
feat(plotly): implement histogram-basic (#379)
claude[bot] 1d5bf65
feat(highcharts): implement histogram-basic (#380)
claude[bot] 1bca5fe
feat(plotly): implement histogram-basic (#414)
claude[bot] 99c4fc5
feat(seaborn): implement histogram-basic (#464)
claude[bot] 4882920
feat(plotly): implement histogram-basic (#466)
claude[bot] 405c694
feat(matplotlib): implement histogram-basic (#477)
claude[bot] 4ad896b
chore: merge main with selenium fix
MarkusNeusinger d08bd6e
feat(bokeh): implement histogram-basic (#309)
claude[bot] 7115cc1
feat(matplotlib): implement histogram-basic (#486)
claude[bot] ed4be4d
feat(matplotlib): implement histogram-basic (#499)
claude[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: altair | ||
| """ | ||
|
|
||
| import altair as alt | ||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| data = pd.DataFrame({"value": np.random.normal(100, 15, 500)}) | ||
|
|
||
| # Create histogram chart | ||
| chart = ( | ||
| alt.Chart(data) | ||
| .mark_bar(color="#306998", opacity=0.8) | ||
| .encode(alt.X("value:Q", bin=alt.Bin(maxbins=30), title="Value"), alt.Y("count()", title="Frequency")) | ||
| .properties(width=1600, height=900, title="Basic Histogram") | ||
| .configure_axis(labelFontSize=16, titleFontSize=20) | ||
| .configure_title(fontSize=20) | ||
| ) | ||
|
|
||
| # Save as PNG (1600 × 900 at scale 3 = 4800 × 2700) | ||
| chart.save("plot.png", scale_factor=3.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: bokeh | ||
| """ | ||
|
|
||
| import numpy as np | ||
| from bokeh.io import export_png | ||
| from bokeh.plotting import figure | ||
|
|
||
|
|
||
| # Data - 500 normally distributed values (mean=100, std=15) | ||
| np.random.seed(42) | ||
| values = np.random.normal(100, 15, 500) | ||
|
|
||
| # Compute histogram bins | ||
| hist, edges = np.histogram(values, bins=30) | ||
|
|
||
| # Create figure (4800 x 2700 px for high resolution) | ||
| p = figure(width=4800, height=2700, title="Basic Histogram", x_axis_label="Value", y_axis_label="Frequency") | ||
|
|
||
| # Draw histogram using quad glyph | ||
| p.quad( | ||
| top=hist, | ||
| bottom=0, | ||
| left=edges[:-1], | ||
| right=edges[1:], | ||
| fill_color="#306998", | ||
| fill_alpha=0.7, | ||
| line_color="white", | ||
| line_width=1, | ||
| ) | ||
|
|
||
| # Style title | ||
| p.title.text_font_size = "20pt" | ||
| p.title.align = "center" | ||
|
|
||
| # Style axis labels | ||
| p.xaxis.axis_label_text_font_size = "20pt" | ||
| p.yaxis.axis_label_text_font_size = "20pt" | ||
| p.xaxis.major_label_text_font_size = "16pt" | ||
| p.yaxis.major_label_text_font_size = "16pt" | ||
|
|
||
| # Style grid - subtle | ||
| p.xgrid.grid_line_alpha = 0.3 | ||
| p.ygrid.grid_line_alpha = 0.3 | ||
|
|
||
| # Ensure y-axis starts at zero | ||
| p.y_range.start = 0 | ||
|
|
||
| # Save output | ||
| export_png(p, filename="plot.png") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: highcharts | ||
| """ | ||
|
|
||
| import tempfile | ||
| import time | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| from highcharts_core.chart import Chart | ||
| from highcharts_core.options import HighchartsOptions | ||
| from highcharts_core.options.series.bar import ColumnSeries | ||
| from selenium import webdriver | ||
| from selenium.webdriver.chrome.options import Options | ||
|
|
||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| values = np.random.normal(100, 15, 500) # 500 values, mean=100, std=15 | ||
|
|
||
| # Calculate histogram bins | ||
| bins = 30 | ||
| counts, bin_edges = np.histogram(values, bins=bins) | ||
|
|
||
| # Create bin labels (center of each bin) | ||
| bin_centers = [(bin_edges[i] + bin_edges[i + 1]) / 2 for i in range(len(counts))] | ||
| bin_labels = [f"{bin_edges[i]:.1f}-{bin_edges[i + 1]:.1f}" for i in range(len(counts))] | ||
|
|
||
| # Create chart with container ID | ||
| chart = Chart(container="container") | ||
| chart.options = HighchartsOptions() | ||
|
|
||
| # Chart configuration | ||
| chart.options.chart = { | ||
| "type": "column", | ||
| "width": 4800, | ||
| "height": 2700, | ||
| "backgroundColor": "#ffffff", | ||
| "spacingBottom": 120, # Add space for x-axis title | ||
| } | ||
|
|
||
| # Title | ||
| chart.options.title = {"text": "Basic Histogram", "style": {"fontSize": "48px", "fontWeight": "bold"}} | ||
|
|
||
| # X-axis configuration | ||
| chart.options.x_axis = { | ||
| "categories": bin_labels, | ||
| "title": {"text": "Value", "style": {"fontSize": "40px"}}, | ||
| "labels": { | ||
| "rotation": 315, # 315 degrees = -45 degrees | ||
| "style": {"fontSize": "28px"}, | ||
| "step": 3, # Show every 3rd label to avoid overlap | ||
| }, | ||
| } | ||
|
|
||
| # Y-axis configuration | ||
| chart.options.y_axis = { | ||
| "title": {"text": "Frequency", "style": {"fontSize": "40px"}}, | ||
| "min": 0, | ||
| "gridLineWidth": 1, | ||
| "gridLineDashStyle": "Dot", | ||
| "gridLineColor": "rgba(0, 0, 0, 0.15)", | ||
| "labels": {"style": {"fontSize": "32px"}}, | ||
| } | ||
|
|
||
| # Create series with histogram data | ||
| series = ColumnSeries() | ||
| series.data = counts.tolist() | ||
| series.name = "Frequency" | ||
| series.color = "#306998" # Python Blue | ||
| series.border_color = "white" | ||
| series.border_width = 1 | ||
|
|
||
| # Plot options for histogram appearance | ||
| chart.options.plot_options = {"column": {"pointPadding": 0, "groupPadding": 0, "borderWidth": 1, "opacity": 0.8}} | ||
|
|
||
| chart.add_series(series) | ||
|
|
||
| # Legend (single series, hide) | ||
| chart.options.legend = {"enabled": False} | ||
|
|
||
| # Credits | ||
| chart.options.credits = {"enabled": False} | ||
|
|
||
| # Download Highcharts JS (required for headless Chrome) | ||
| highcharts_url = "https://code.highcharts.com/highcharts.js" | ||
| with urllib.request.urlopen(highcharts_url, timeout=30) as response: | ||
| highcharts_js = response.read().decode("utf-8") | ||
|
|
||
| # Generate HTML with inline scripts | ||
| html_str = chart.to_js_literal() | ||
| html_content = f"""<!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <script>{highcharts_js}</script> | ||
| </head> | ||
| <body style="margin:0;"> | ||
| <div id="container" style="width: 4800px; height: 2700px;"></div> | ||
| <script>{html_str}</script> | ||
| </body> | ||
| </html>""" | ||
|
|
||
| # Write temp HTML and take screenshot | ||
| with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False, encoding="utf-8") as f: | ||
| f.write(html_content) | ||
| temp_path = f.name | ||
|
|
||
| chrome_options = Options() | ||
| chrome_options.add_argument("--headless") | ||
| chrome_options.add_argument("--no-sandbox") | ||
| chrome_options.add_argument("--disable-dev-shm-usage") | ||
| chrome_options.add_argument("--disable-gpu") | ||
| chrome_options.add_argument("--window-size=4800,2800") # Slightly larger to capture full chart | ||
|
|
||
| driver = webdriver.Chrome(options=chrome_options) | ||
| driver.get(f"file://{temp_path}") | ||
| time.sleep(5) # Wait for chart to render | ||
| driver.save_screenshot("plot.png") | ||
| driver.quit() | ||
|
|
||
| Path(temp_path).unlink() # Clean up temp file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: letsplot | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| from lets_plot import LetsPlot, aes, element_text, geom_histogram, ggplot, ggsave, ggsize, labs, theme, theme_minimal | ||
|
|
||
|
|
||
| LetsPlot.setup_html() | ||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| data = pd.DataFrame({"value": np.random.normal(100, 15, 500)}) | ||
|
|
||
| # Plot | ||
| plot = ( | ||
| ggplot(data, aes(x="value")) | ||
| + geom_histogram(bins=30, fill="#306998", color="white", alpha=0.8) | ||
| + labs(x="Value", y="Frequency", title="Basic Histogram") | ||
| + theme_minimal() | ||
| + theme(plot_title=element_text(size=20), axis_title=element_text(size=20), axis_text=element_text(size=16)) | ||
| + ggsize(1600, 900) | ||
| ) | ||
|
|
||
| # Save - scale 3x to get 4800 x 2700 px | ||
| ggsave(plot, "plot.png", path=".", scale=3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: matplotlib | ||
| """ | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| data = pd.DataFrame({"value": np.random.normal(100, 15, 500)}) | ||
|
|
||
| # Create plot | ||
| fig, ax = plt.subplots(figsize=(16, 9)) | ||
| ax.hist(data["value"], bins=30, alpha=0.8, color="#306998", edgecolor="white", linewidth=0.5) | ||
|
|
||
| # Labels and styling | ||
| ax.set_xlabel("Value", fontsize=20) | ||
| ax.set_ylabel("Frequency", fontsize=20) | ||
| ax.set_title("Basic Histogram", fontsize=20) | ||
| ax.tick_params(axis="both", labelsize=16) | ||
| ax.grid(True, alpha=0.3, axis="y") | ||
|
|
||
| plt.tight_layout() | ||
| plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: plotly | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import plotly.graph_objects as go | ||
|
|
||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| values = np.random.normal(100, 15, 500) # 500 values, mean=100, std=15 | ||
|
|
||
| # Create figure | ||
| fig = go.Figure() | ||
| fig.add_trace(go.Histogram(x=values, marker={"color": "#306998", "line": {"color": "white", "width": 1}}, opacity=0.85)) | ||
|
|
||
| # Layout | ||
| fig.update_layout( | ||
| title={"text": "Basic Histogram", "font": {"size": 40}, "x": 0.5, "xanchor": "center"}, | ||
| xaxis_title="Value", | ||
| yaxis_title="Frequency", | ||
| template="plotly_white", | ||
| font={"size": 32}, | ||
| xaxis={"title_font": {"size": 40}, "tickfont": {"size": 32}, "showgrid": True, "gridcolor": "rgba(0,0,0,0.1)"}, | ||
| yaxis={"title_font": {"size": 40}, "tickfont": {"size": 32}, "showgrid": True, "gridcolor": "rgba(0,0,0,0.1)"}, | ||
| bargap=0.05, | ||
| ) | ||
|
|
||
| # Save | ||
| fig.write_image("plot.png", width=1600, height=900, scale=3) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| histogram-basic: Basic Histogram | ||
| Library: plotnine | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| from plotnine import aes, element_text, geom_histogram, ggplot, labs, theme, theme_minimal | ||
|
|
||
|
|
||
| # Data | ||
| np.random.seed(42) | ||
| data = pd.DataFrame({"value": np.random.normal(100, 15, 500)}) | ||
|
|
||
| # Plot | ||
| plot = ( | ||
| ggplot(data, aes(x="value")) | ||
| + geom_histogram(bins=30, fill="#306998", color="white", alpha=0.8) | ||
| + labs(x="Value", y="Frequency", title="Basic Histogram") | ||
| + theme_minimal() | ||
| + theme( | ||
| figure_size=(16, 9), | ||
| plot_title=element_text(size=20), | ||
| axis_title=element_text(size=20), | ||
| axis_text=element_text(size=16), | ||
| ) | ||
| ) | ||
|
|
||
| # Save | ||
| plot.save("plot.png", dpi=300) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| """ | ||||||
| histogram-basic: Basic Histogram | ||||||
| Library: pygal | ||||||
| """ | ||||||
|
|
||||||
| import numpy as np | ||||||
| import pygal | ||||||
| from pygal.style import Style | ||||||
|
|
||||||
|
|
||||||
| # Data | ||||||
| np.random.seed(42) | ||||||
| values = np.random.normal(100, 15, 500) # 500 values, mean=100, std=15 | ||||||
|
|
||||||
| # Calculate histogram bins | ||||||
| counts, bin_edges = np.histogram(values, bins=20) | ||||||
|
||||||
| counts, bin_edges = np.histogram(values, bins=20) | |
| counts, bin_edges = np.histogram(values, bins=30) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The histogram should specify the number of bins to match the spec and other library implementations. All other implementations use 30 bins explicitly. Add
nbins=30parameter to thego.Histogramconstructor.Suggested fix: