{"spec_id":"ohlc-bar","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nohlc-bar: OHLC Bar Chart\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-17\n\"\"\"\n\nimport os\nimport sys\n\n\n# Remove current directory from path to avoid naming conflicts\nsys.path = [p for p in sys.path if p not in (\"\", \".\", os.path.dirname(__file__))]\n\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\n\n\n# Theme tokens (see prompts/default-style-guide.md)\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\n# Okabe-Ito palette for up/down coloring\nBRAND = \"#009E73\"  # Position 1 - bluish green, first series\nUP_COLOR = BRAND  # Use brand green for up days\nDOWN_COLOR = \"#AE3030\"  # imprint red — down days\n\n# Data - Generate realistic stock price data for 45 trading days\nnp.random.seed(42)\n\ndates = pd.date_range(start=\"2024-06-01\", periods=45, freq=\"B\")  # Business days\n\n# Generate realistic price movement with trends\nbase_price = 150.0\nreturns = np.random.normal(0.001, 0.02, 45)  # Daily returns\ncumulative = np.cumprod(1 + returns)\nclose_prices = base_price * cumulative\n\n# Generate OHLC data with realistic relationships\ndata = []\nfor i, date in enumerate(dates):\n    close = close_prices[i]\n    # Open is close of previous day (or base for first day)\n    open_price = close_prices[i - 1] if i > 0 else base_price\n\n    # High and low based on intraday volatility\n    intraday_range = close * np.random.uniform(0.01, 0.03)\n    high = max(open_price, close) + np.random.uniform(0, intraday_range)\n    low = min(open_price, close) - np.random.uniform(0, intraday_range)\n\n    data.append({\"date\": date, \"open\": open_price, \"high\": high, \"low\": low, \"close\": close})\n\ndf = pd.DataFrame(data)\n\n# Create OHLC chart using Plotly's native OHLC trace\nfig = go.Figure(\n    data=go.Ohlc(\n        x=df[\"date\"],\n        open=df[\"open\"],\n        high=df[\"high\"],\n        low=df[\"low\"],\n        close=df[\"close\"],\n        increasing={\"line\": {\"color\": UP_COLOR, \"width\": 2}},\n        decreasing={\"line\": {\"color\": DOWN_COLOR, \"width\": 2}},\n        name=\"Price\",\n    )\n)\n\n# Update layout for 4800x2700 canvas with theme-adaptive chrome\nfig.update_layout(\n    title={\"text\": \"ohlc-bar · plotly · anyplot.ai\", \"font\": {\"size\": 28, \"color\": INK}, \"x\": 0.5, \"xanchor\": \"center\"},\n    xaxis={\n        \"title\": {\"text\": \"Date\", \"font\": {\"size\": 22, \"color\": INK}},\n        \"tickfont\": {\"size\": 18, \"color\": INK_SOFT},\n        \"gridcolor\": GRID,\n        \"gridwidth\": 1,\n        \"linecolor\": INK_SOFT,\n        \"rangeslider\": {\"visible\": False},\n        \"tickformat\": \"%b %d\",\n    },\n    yaxis={\n        \"title\": {\"text\": \"Price (USD)\", \"font\": {\"size\": 22, \"color\": INK}},\n        \"tickfont\": {\"size\": 18, \"color\": INK_SOFT},\n        \"tickprefix\": \"$\",\n        \"gridcolor\": GRID,\n        \"gridwidth\": 1,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": INK_SOFT,\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    showlegend=False,\n    margin={\"l\": 100, \"r\": 80, \"t\": 120, \"b\": 100},\n)\n\n# Save outputs\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}