Skip to content

Commit 75253be

Browse files
upadting figures and cleaning
1 parent cb0e01f commit 75253be

1 file changed

Lines changed: 48 additions & 105 deletions

File tree

Code/Plotting/fig_05.ipynb

Lines changed: 48 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,6 @@
250250
"ds_wT_Jun_month]"
251251
]
252252
},
253-
{
254-
"cell_type": "markdown",
255-
"metadata": {},
256-
"source": [
257-
"# Deleted particles"
258-
]
259-
},
260-
{
261-
"cell_type": "code",
262-
"execution_count": 12,
263-
"metadata": {},
264-
"outputs": [],
265-
"source": [
266-
"\n",
267-
"# these are matplotlib.patch.Patch properties\n",
268-
"props = dict(boxstyle='round', facecolor='wheat', alpha=.5)\n"
269-
]
270-
},
271253
{
272254
"cell_type": "markdown",
273255
"metadata": {},
@@ -289,7 +271,7 @@
289271
" lonmax=-21., \n",
290272
" latmin=32.5, \n",
291273
" latmax=36.5\n",
292-
")#lomin -35 #lomax -18 # lamin 30 # lamax 40"
274+
")"
293275
]
294276
},
295277
{
@@ -314,116 +296,77 @@
314296
"metadata": {},
315297
"outputs": [],
316298
"source": [
317-
"nbins = (60, 40)\n",
318-
"\n",
319-
"xmin = subregion.lonmin\n",
320-
"xmax = subregion.lonmax\n",
321-
"ymin = subregion.latmin\n",
322-
"ymax = subregion.latmax\n",
299+
"def calc_hist2d(dsp, nbins, nsubregion):\n",
300+
" \"\"\"\n",
301+
" xxxx\n",
302+
" dsp: xarray dataset \n",
303+
" \"\"\" \n",
304+
" xmin = nsubregion.lonmin\n",
305+
" xmax = nsubregion.lonmax\n",
306+
" ymin = nsubregion.latmin\n",
307+
" ymax = nsubregion.latmax\n",
308+
" \n",
309+
" lon_end_nonans, lat_end_nonans = rem_nans(dsp)\n",
310+
" counts, xedges, yedges = np.histogram2d(lon_end_nonans, lat_end_nonans, bins=nbins, range=((xmin, xmax), (ymin, ymax)))\n",
323311
"\n",
324-
"vmin=0.\n",
325-
"vmax=30."
326-
]
327-
},
328-
{
329-
"cell_type": "markdown",
330-
"metadata": {},
331-
"source": [
332-
"# Histogram 1D"
312+
" return counts.ravel()\n",
313+
" "
333314
]
334315
},
335316
{
336317
"cell_type": "code",
337-
"execution_count": 16,
318+
"execution_count": null,
338319
"metadata": {},
339320
"outputs": [],
340321
"source": [
341-
"ymax_1d = .2\n",
342-
"xmax_1d = 90\n",
343-
"\n",
344-
"nbins_1d = 20"
322+
"bins_2d = (60, 40) # --> 0.1 degree"
345323
]
346324
},
347325
{
348326
"cell_type": "code",
349-
"execution_count": 17,
327+
"execution_count": null,
350328
"metadata": {},
351329
"outputs": [],
352330
"source": [
353-
"def plot_hist1d_particles_b(dsp, axn, nbins_1d, ntitle, labelf, ncolor='b'):\n",
354-
" \"\"\"\n",
355-
" \"\"\" \n",
356-
" ######\n",
357-
" # Title\n",
358-
" if ntitle in ntitles[0:6]:\n",
359-
" nyear = '2009'\n",
360-
" elif ntitle in ntitles[6::]:\n",
361-
" nyear = '2010'\n",
362-
" else:\n",
363-
" print('Error nyear')\n",
364-
" dgdsgsg\n",
365-
" \n",
366-
" strtitle = ntitle + ' ' + nyear\n",
367-
" axn.set_title(strtitle, size=16)\n",
368-
" ######\n",
369-
" \n",
370-
" lon_end_nonans, lat_end_nonans = rem_nans(dsp)\n",
371-
" counts, xedges, yedges = np.histogram2d(lon_end_nonans, lat_end_nonans, bins=nbins, range=((xmin, xmax), (ymin, ymax)))\n",
331+
"counts_nT = np.ones((12, 60*40)) * np.nan\n",
332+
"counts_wT = np.ones((12, 60*40)) * np.nan\n",
372333
"\n",
373-
" axn.hist(counts.ravel(), bins=nbins_1d, density=True, color=ncolor, alpha=.5, label=labelf)\n",
374-
" axn.set_ylim([0, ymax_1d])\n",
375-
" axn.set_xlim([0, xmax_1d])\n",
376-
" axn.grid()\n",
377-
" axn.axvline(x=counts.ravel().max(), color=ncolor)\n",
378-
" #print(counts.ravel().max())\n",
379-
" skw_2D = scipy.stats.skew(counts.ravel())\n",
380-
" # axn.annotate('Skewness = ' + str(np.round(scipy.stats.skew(counts.ravel()), 2)),\n",
381-
" # xy=(22, .17), xycoords='data', size=16)\n",
382-
" return skw_2D, counts.ravel()\n",
383-
" "
334+
"for ii in range(0, len(ntitles)):\n",
335+
" counts_nT[ii,:] = calc_hist2d(dsps_nT[ii], bins_2d, subregion)\n",
336+
" counts_wT[ii,:] = calc_hist2d(dsps_wT[ii], bins_2d, subregion)\n"
384337
]
385338
},
386339
{
387-
"cell_type": "code",
388-
"execution_count": 18,
340+
"cell_type": "markdown",
389341
"metadata": {},
390-
"outputs": [],
391342
"source": [
392-
"#https://matplotlib.org/3.3.4/gallery/recipes/placing_text_boxes.html\n",
393-
"\n",
394-
"# these are matplotlib.patch.Patch properties\n",
395-
"props = dict(boxstyle='round', facecolor='wheat', alpha=1) # alpha=\n"
343+
"# Histogram 1D"
396344
]
397345
},
398346
{
399347
"cell_type": "markdown",
400348
"metadata": {},
401349
"source": [
402-
"# Defining same binsize for all months instead of bin number"
350+
"## Doing it with number of bins:"
403351
]
404352
},
405353
{
406-
"cell_type": "code",
407-
"execution_count": 19,
354+
"cell_type": "markdown",
408355
"metadata": {},
409-
"outputs": [],
410356
"source": [
411-
"ymax_1d = .15\n",
412-
"\n",
413-
"bins_list = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]\n",
414-
"# specify bin start and end points"
357+
"* 10 max 70:"
415358
]
416359
},
417360
{
418361
"cell_type": "code",
419-
"execution_count": 20,
362+
"execution_count": 16,
420363
"metadata": {},
421364
"outputs": [],
422365
"source": [
423-
"ymax_1d = .15\n",
366+
"bins_list = 10\n",
424367
"\n",
425-
"bins_list = [0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90]\n",
426-
"# specify bin start and end points"
368+
"ymax_1d = 0.185\n",
369+
"xmax_1d = 77"
427370
]
428371
},
429372
{
@@ -445,8 +388,6 @@
445388
}
446389
],
447390
"source": [
448-
"xmax_1d = 80\n",
449-
"\n",
450391
"fig = plt.figure(figsize=(16,13)) #(17,5)\n",
451392
"\n",
452393
"#cbar_ticks = [0.005, 0.0055, 0.006, 0.0065, 0.007, 0.0075, 0.008, 0.0085, 0.009] \n",
@@ -472,23 +413,31 @@
472413
" strtitle = ntitle + '. ' + nyear\n",
473414
" ax1.set_title(strtitle, size=16)\n",
474415
" ######\n",
416+
" \n",
417+
" counts_nT_1, binEdges_nT = np.histogram(counts_nT[ii,:], bins=bins_list, density=True)\n",
418+
" counts_wT_1, binEdges_wT = np.histogram(counts_wT[ii,:], bins=bins_list, density=True)\n",
419+
" \n",
420+
" bincenters_nT = 0.5 * (binEdges_nT[1:] + binEdges_nT[:-1])\n",
421+
" bincenters_wT = 0.5 * (binEdges_wT[1:] + binEdges_wT[:-1])\n",
475422
" \n",
476-
" ax1.hist(counts_nT[ii,:], bins=bins_list, density=True, alpha=.5, label='No tidal forcing', color='b')\n",
423+
" ax1.plot(bincenters_nT, counts_nT_1, '.-', color='C0', label='No tidal forcing', linewidth=2, markersize=10)# , linewidth=4\n",
477424
" ax1.set_ylim([0, ymax_1d])\n",
478425
" ax1.set_xlim([0, xmax_1d])\n",
479-
" ax1.axvline(x=counts_nT[ii,:].max(), color='b')\n",
426+
" ax1.axvline(x=counts_nT[ii,:].max(), linestyle='--', color='C0')\n",
480427
" \n",
481-
" ax1.hist(counts_wT[ii,:], bins=bins_list, density=True, alpha=.5, label='Tidal forcing', color='r')\n",
428+
" ax1.plot(bincenters_wT, counts_wT_1, '.-', color='C3', label='Tidal forcing', linewidth=2, markersize=10)# , linewidth=4\n",
482429
" ax1.set_ylim([0, ymax_1d])\n",
483430
" ax1.set_xlim([0, xmax_1d])\n",
484-
" ax1.axvline(x=counts_wT[ii,:].max(), color='r')\n",
431+
" ax1.axvline(x=counts_wT[ii,:].max(), linestyle='--', color='C3')\n",
485432
" \n",
486433
" #skw_2D_wT, _ = plot_hist1d_particles_b(dsps_wT[ii], ax1, bins_list, ntitles[ii], labelf='Tidal', ncolor='r')\n",
487434
" ax1.grid()\n",
488435
" ax1.tick_params(axis='both', which='major', labelsize=14)\n",
489436
"\n",
490437
" if ii == 0:\n",
491-
" ax1.legend(loc=0, fontsize=14)\n",
438+
" legend = ax1.legend(loc=0, fontsize=12)\n",
439+
" legend.get_frame().set_alpha(None)\n",
440+
" legend.get_frame().set_facecolor('white')\n",
492441
" if ((ii==4)):\n",
493442
" ax1.set_ylabel('Normalized frequency', size=20) # Normalized bin counts\n",
494443
" if ((ii==9)):\n",
@@ -497,14 +446,8 @@
497446
" ax1.axes.xaxis.set_ticklabels([])\n",
498447
" if (ii != 0) & (ii != 4) & (ii != 8) :\n",
499448
" ax1.axes.yaxis.set_ticklabels([])\n",
500-
"# textstr = '\\n'.join((\n",
501-
"# r'$nT=%.2f$' % (skw_2D_nT, ),\n",
502-
"# r'$wT=%.2f$' % (skw_2D_wT, )))\n",
503-
"# # place a text box in upper left in axes coords\n",
504-
"# ax1.text(0.55, 0.95, textstr, transform=ax1.transAxes, fontsize=14,\n",
505-
"# verticalalignment='top', bbox=props)\n",
506-
"\n",
507-
"plt.savefig('figs/' + 'hist1d_nT_wT_monthly_nobox.jpg', dpi=300)\n",
449+
" \n",
450+
"plt.savefig('../../Figures/' + 'hist1d_nT_wT_monthly_nobox.jpg', dpi=300)\n",
508451
" \n",
509452
"plt.show()\n"
510453
]
@@ -535,7 +478,7 @@
535478
"name": "python",
536479
"nbconvert_exporter": "python",
537480
"pygments_lexer": "ipython3",
538-
"version": "3.8.11"
481+
"version": "3.11.6"
539482
}
540483
},
541484
"nbformat": 4,

0 commit comments

Comments
 (0)