{"spec_id":"indicator-rsi","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nindicator-rsi: RSI Technical Indicator Chart\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 81/100 | Updated: 2026-05-16\n\"\"\"\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\n\n\n# Data - Generate realistic RSI values with market-like behavior\nnp.random.seed(42)\nn_periods = 120\n\n# Create date range for trading days\ndates = pd.date_range(start=\"2024-01-02\", periods=n_periods, freq=\"B\")\n\n# Generate RSI values with realistic market dynamics\n# RSI tends to mean-revert and oscillate between zones\nrsi_values = np.zeros(n_periods)\nrsi_values[0] = 50  # Start at neutral\n\nfor i in range(1, n_periods):\n    # Mean-reverting random walk with momentum\n    mean_reversion = 0.05 * (50 - rsi_values[i - 1])\n    momentum = np.random.randn() * 5\n    rsi_values[i] = rsi_values[i - 1] + mean_reversion + momentum\n    # Clamp to valid RSI range\n    rsi_values[i] = np.clip(rsi_values[i], 5, 95)\n\n# Create some realistic market events - push into overbought/oversold zones\nrsi_values[15:25] = rsi_values[15:25] + 18  # Bull run into overbought\nrsi_values[45:55] = rsi_values[45:55] - 15  # Bear drop into oversold\nrsi_values[80:90] = rsi_values[80:90] + 12  # Another overbought push\nrsi_values = np.clip(rsi_values, 15, 85)  # Keep within typical RSI bounds\n\ndf = pd.DataFrame({\"date\": dates, \"rsi\": rsi_values})\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9))\n\n# Shade overbought zone (70-100)\nax.axhspan(70, 100, alpha=0.15, color=\"#D32F2F\", label=\"Overbought Zone\")\n\n# Shade oversold zone (0-30)\nax.axhspan(0, 30, alpha=0.15, color=\"#388E3C\", label=\"Oversold Zone\")\n\n# Add threshold lines\nax.axhline(y=70, color=\"#D32F2F\", linestyle=\"--\", linewidth=2, alpha=0.8)\nax.axhline(y=30, color=\"#388E3C\", linestyle=\"--\", linewidth=2, alpha=0.8)\nax.axhline(y=50, color=\"#757575\", linestyle=\"-\", linewidth=1.5, alpha=0.6)\n\n# Plot RSI line using seaborn\nsns.lineplot(data=df, x=\"date\", y=\"rsi\", ax=ax, color=\"#306998\", linewidth=3)\n\n# Mark overbought and oversold points\noverbought_mask = df[\"rsi\"] >= 70\noversold_mask = df[\"rsi\"] <= 30\n\nif overbought_mask.any():\n    sns.scatterplot(data=df[overbought_mask], x=\"date\", y=\"rsi\", ax=ax, color=\"#D32F2F\", s=100, zorder=5, legend=False)\n\nif oversold_mask.any():\n    sns.scatterplot(data=df[oversold_mask], x=\"date\", y=\"rsi\", ax=ax, color=\"#388E3C\", s=100, zorder=5, legend=False)\n\n# Style\nax.set_ylim(0, 100)\nax.set_xlabel(\"Date\", fontsize=20)\nax.set_ylabel(\"RSI (14-period)\", fontsize=20)\nax.set_title(\"indicator-rsi · seaborn · pyplots.ai\", fontsize=24)\nax.tick_params(axis=\"both\", labelsize=16)\nax.grid(True, alpha=0.3, linestyle=\"--\")\n\n# Add text annotations for zones\nax.text(\n    df[\"date\"].iloc[-1],\n    85,\n    \"Overbought (>70)\",\n    fontsize=14,\n    ha=\"right\",\n    va=\"center\",\n    color=\"#D32F2F\",\n    fontweight=\"bold\",\n)\nax.text(\n    df[\"date\"].iloc[-1], 15, \"Oversold (<30)\", fontsize=14, ha=\"right\", va=\"center\", color=\"#388E3C\", fontweight=\"bold\"\n)\nax.text(df[\"date\"].iloc[-1], 52, \"Neutral (50)\", fontsize=14, ha=\"right\", va=\"center\", color=\"#757575\")\n\n# Format x-axis dates\nfig.autofmt_xdate(rotation=30)\n\nplt.tight_layout()\nplt.savefig(\"plot.png\", dpi=300, bbox_inches=\"tight\")\n"}