{"spec_id":"line-timeseries","library":"bokeh","language":"python","code":"\"\"\" anyplot.ai\nline-timeseries: Time Series Line Plot\nLibrary: bokeh 3.9.0 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-09\n\"\"\"\n\nimport os\nimport sys\nimport time\nfrom pathlib import Path\n\nimport numpy as np\nimport pandas as pd\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\n\n# Fix name collision: temporarily remove local directory from sys.path\n_local_path = str(Path.cwd())\n_sys_path_backup = sys.path.copy()\nsys.path = [p for p in sys.path if p != \"\" and p != \".\" and p != _local_path]\n\nfrom bokeh.io import output_file, save\nfrom bokeh.models import ColumnDataSource\nfrom bokeh.plotting import figure\n\n\nsys.path = _sys_path_backup\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Stock price simulation over one year\nnp.random.seed(42)\ndates = pd.date_range(start=\"2024-01-01\", end=\"2024-12-31\", freq=\"D\")\nn_points = len(dates)\n\n# Simulate stock price with trend, seasonality, and noise\nbase_price = 150\ntrend = np.linspace(0, 30, n_points)\nseasonality = 10 * np.sin(np.linspace(0, 4 * np.pi, n_points))\nnoise = np.cumsum(np.random.randn(n_points) * 0.8)\nprices = base_price + trend + seasonality + noise\nprices = np.maximum(prices, 50)\n\nsource = ColumnDataSource(data={\"date\": dates, \"price\": prices})\n\n# Create figure\np = figure(\n    width=4800,\n    height=2700,\n    title=\"line-timeseries · bokeh · anyplot.ai\",\n    x_axis_label=\"Date\",\n    y_axis_label=\"Stock Price (USD)\",\n    x_axis_type=\"datetime\",\n    tools=\"pan,wheel_zoom,box_zoom,reset,save\",\n)\n\n# Plot the line\np.line(x=\"date\", y=\"price\", source=source, line_width=3, line_color=BRAND, legend_label=\"Stock Price\")\n\n# Styling - text sizes for 4800x2700 px canvas\np.title.text_font_size = \"28pt\"\np.title.text_color = INK\np.xaxis.axis_label_text_font_size = \"22pt\"\np.xaxis.axis_label_text_color = INK\np.yaxis.axis_label_text_font_size = \"22pt\"\np.yaxis.axis_label_text_color = INK\np.xaxis.major_label_text_font_size = \"18pt\"\np.xaxis.major_label_text_color = INK_SOFT\np.yaxis.major_label_text_font_size = \"18pt\"\np.yaxis.major_label_text_color = INK_SOFT\n\n# Grid styling\np.xgrid.grid_line_alpha = 0.10\np.ygrid.grid_line_alpha = 0.10\np.xgrid.grid_line_color = INK\np.ygrid.grid_line_color = INK\n\n# Legend styling\np.legend.location = \"top_left\"\np.legend.label_text_font_size = \"18pt\"\np.legend.label_text_color = INK_SOFT\np.legend.background_fill_color = ELEVATED_BG\np.legend.border_line_color = INK_SOFT\np.legend.border_line_width = 1\np.legend.glyph_height = 25\np.legend.glyph_width = 40\n\n# Axis styling\np.xaxis.major_label_orientation = 0.8\np.xaxis.axis_line_color = INK_SOFT\np.yaxis.axis_line_color = INK_SOFT\np.xaxis.major_tick_line_color = INK_SOFT\np.yaxis.major_tick_line_color = INK_SOFT\n\n# Background\np.background_fill_color = PAGE_BG\np.border_fill_color = PAGE_BG\np.outline_line_color = INK_SOFT\n\n# Save HTML\noutput_file(f\"plot-{THEME}.html\")\nsave(p)\n\n# Screenshot with headless Chrome\nW, H = 4800, 2700\nopts = Options()\nfor arg in (\n    \"--headless=new\",\n    \"--no-sandbox\",\n    \"--disable-dev-shm-usage\",\n    \"--disable-gpu\",\n    f\"--window-size={W},{H}\",\n    \"--hide-scrollbars\",\n):\n    opts.add_argument(arg)\ndriver = webdriver.Chrome(options=opts)\ndriver.set_window_size(W, H)\ndriver.get(f\"file://{Path(f'plot-{THEME}.html').resolve()}\")\ntime.sleep(3)\ndriver.save_screenshot(f\"plot-{THEME}.png\")\ndriver.quit()\n"}