Skip to content

Commit

Permalink
50 / 60 : add x v plot using matplotlib.gridspec
Browse files Browse the repository at this point in the history
help from Gemini
  • Loading branch information
beachdweller committed May 22, 2024
1 parent 1f79e88 commit 88a340b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion 50_ode/60_Duffing_Oscillator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,15 @@
" \n",
" t_out, x_out = ode_solver.rk4(slope, t_array, x_0)\n",
" x_out = np.array(x_out)\n",
" _, axs = plt.subplots(2, 1, figsize=figsize)\n",
" fig = plt.figure(figsize=figsize)\n",
" gs = mg.GridSpec(2, 2, height_ratios=[1, 1], width_ratios=[1, 1])\n",
"\n",
" axs = (\n",
" fig.add_subplot(gs[0, 0]),\n",
" fig.add_subplot(gs[1, 0]),\n",
" fig.add_subplot(gs[:, 1])\n",
" )\n",
" \n",
" for k in range(2):\n",
" axs[k].plot(t_out, x_out[:, k], label='Duffing')\n",
" axs[k].plot(t_out, x_out[:, k+2], label='Linear')\n",
Expand All @@ -206,6 +213,12 @@
" axs[0].set_ylabel('$x(t)$')\n",
" axs[1].set_ylabel(r'$\\frac{d}{dt}x(t)$')\n",
"\n",
" axs[2].plot(x_out[:, 0], x_out[:, 1], label='Duffing')\n",
" axs[2].plot(x_out[:, 2], x_out[:, 3], label='Linear')\n",
" axs[2].grid(True)\n",
" axs[2].set_xlabel('$x(t)$')\n",
" axs[2].set_ylabel(r'$\\frac{d}{dt}x(t)$')\n",
"\n",
" return axs\n",
"\n"
]
Expand Down

0 comments on commit 88a340b

Please sign in to comment.