|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | area-basic: Basic Area Chart |
3 | 3 | Library: highcharts 1.10.3 | Python 3.14.2 |
4 | | -Quality: 74/100 | Created: 2025-12-23 |
| 4 | +Quality: /100 | Updated: 2026-02-11 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import tempfile |
|
31 | 31 | chart = Chart(container="container") |
32 | 32 | chart.options = HighchartsOptions() |
33 | 33 |
|
34 | | -# Chart configuration |
| 34 | +# Chart configuration — generous bottom margin to ensure x-axis title renders fully |
35 | 35 | chart.options.chart = { |
36 | 36 | "type": "area", |
37 | 37 | "width": 4800, |
38 | 38 | "height": 2700, |
39 | 39 | "backgroundColor": "#ffffff", |
40 | | - "marginBottom": 200, |
41 | | - "marginLeft": 200, |
| 40 | + "marginBottom": 300, |
| 41 | + "marginLeft": 220, |
| 42 | + "spacingBottom": 40, |
42 | 43 | } |
43 | 44 |
|
44 | 45 | # Title |
|
47 | 48 | "style": {"fontSize": "72px", "fontWeight": "bold"}, |
48 | 49 | } |
49 | 50 |
|
50 | | -# X-axis |
| 51 | +# Subtitle for data context |
| 52 | +chart.options.subtitle = { |
| 53 | + "text": "Daily Website Visitors Over One Month", |
| 54 | + "style": {"fontSize": "42px", "color": "#666666"}, |
| 55 | +} |
| 56 | + |
| 57 | +# X-axis — explicit margin and offset to prevent title clipping |
51 | 58 | chart.options.x_axis = { |
52 | | - "title": {"text": "Day of Month", "style": {"fontSize": "48px"}}, |
53 | | - "labels": {"style": {"fontSize": "36px"}}, |
| 59 | + "title": {"text": "Day of Month", "style": {"fontSize": "48px"}, "margin": 30}, |
| 60 | + "labels": {"style": {"fontSize": "36px"}, "y": 45}, |
54 | 61 | "gridLineWidth": 1, |
55 | 62 | "gridLineColor": "rgba(0, 0, 0, 0.1)", |
| 63 | + "tickInterval": 1, |
56 | 64 | } |
57 | 65 |
|
58 | | -# Y-axis — set min close to data range to avoid wasted whitespace |
| 66 | +# Y-axis — min near data floor to maximize visual resolution of the data range |
59 | 67 | chart.options.y_axis = { |
60 | 68 | "title": {"text": "Daily Visitors (count)", "style": {"fontSize": "48px"}}, |
61 | 69 | "labels": {"style": {"fontSize": "36px"}}, |
62 | 70 | "gridLineWidth": 1, |
63 | 71 | "gridLineColor": "rgba(0, 0, 0, 0.1)", |
64 | | - "min": 1000, |
| 72 | + "min": 1500, |
| 73 | + "startOnTick": False, |
65 | 74 | } |
66 | 75 |
|
67 | 76 | # Plot options with semi-transparent fill and gradient |
68 | 77 | chart.options.plot_options = { |
69 | 78 | "area": { |
70 | 79 | "fillColor": { |
71 | 80 | "linearGradient": {"x1": 0, "y1": 0, "x2": 0, "y2": 1}, |
72 | | - "stops": [[0, "rgba(48, 105, 152, 0.5)"], [1, "rgba(48, 105, 152, 0.1)"]], |
| 81 | + "stops": [[0, "rgba(48, 105, 152, 0.5)"], [1, "rgba(48, 105, 152, 0.05)"]], |
73 | 82 | }, |
74 | 83 | "lineWidth": 4, |
75 | | - "marker": {"enabled": True, "radius": 8, "fillColor": "#306998"}, |
| 84 | + "marker": {"enabled": True, "radius": 6, "fillColor": "#306998"}, |
76 | 85 | "color": "#306998", |
77 | 86 | "tooltip": {"headerFormat": "<b>Day {point.x}</b><br/>", "pointFormat": "Visitors: {point.y:,.0f}"}, |
78 | 87 | } |
79 | 88 | } |
80 | 89 |
|
81 | | -# Legend |
82 | | -chart.options.legend = {"enabled": False} |
| 90 | +# Legend — enabled with styling for single series identification |
| 91 | +chart.options.legend = { |
| 92 | + "enabled": True, |
| 93 | + "itemStyle": {"fontSize": "36px", "fontWeight": "normal"}, |
| 94 | + "align": "right", |
| 95 | + "verticalAlign": "top", |
| 96 | + "layout": "horizontal", |
| 97 | + "x": -40, |
| 98 | + "y": 60, |
| 99 | +} |
| 100 | + |
| 101 | +# Credits off |
| 102 | +chart.options.credits = {"enabled": False} |
83 | 103 |
|
84 | 104 | # Add series |
85 | 105 | series = AreaSeries() |
|
111 | 131 | f.write(html_content) |
112 | 132 | temp_path = f.name |
113 | 133 |
|
114 | | -# Also save HTML for interactive version |
115 | | -with open("plot.html", "w", encoding="utf-8") as f: |
116 | | - # For standalone HTML, use CDN link |
117 | | - standalone_html = f"""<!DOCTYPE html> |
118 | | -<html> |
119 | | -<head> |
120 | | - <meta charset="utf-8"> |
121 | | - <script src="https://code.highcharts.com/highcharts.js"></script> |
122 | | -</head> |
123 | | -<body style="margin:0;"> |
124 | | - <div id="container" style="width: 100%; height: 100vh;"></div> |
125 | | - <script>{html_str}</script> |
126 | | -</body> |
127 | | -</html>""" |
128 | | - f.write(standalone_html) |
129 | | - |
130 | 134 | chrome_options = Options() |
131 | 135 | chrome_options.add_argument("--headless") |
132 | 136 | chrome_options.add_argument("--no-sandbox") |
|
0 commit comments