-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotting.py
2008 lines (1603 loc) · 90.6 KB
/
plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf8 -*-
"""
This module contains functions for plotting observed and synthetic spectra.
"""
from __future__ import print_function
from __future__ import division
import numpy as np
import matplotlib.pyplot as _plt
import matplotlib.ticker as ticker
import matplotlib.colors
import matplotlib
import abundutils as _au
import satlas as _sa
import scipy.interpolate as si
import bisect
import ewutils
import astropy.units
def plot_stuff(result_pair):
"""
This function plots arbitrary stuff. It is not always constant what it does, since
it might be edited. It takes a single required argument
result_pair : An instance of ResultPair that contains the result of a calculation.
"""
result_chi = result_pair.result_chi
result_ew = result_pair.result_ew
regions = [r.region for r in result_chi.region_result]
regions_sorted = sorted(regions, key = lambda r: r.lab_wav)
# *** Plot how the shift and equivalent width relate to each other
if False:
shifts = [1e3*r.best_shift for r in result_chi.region_result]
ews = [r.best_eq_width for r in result_ew.region_result]
_plt.plot(ews, shifts, ".")
_plt.ylabel(u"Shift [mÅ]", fontsize = plot_font_size)
_plt.xlabel("EW [" + str(result_ew.region_result[0].eq_width_unit) + "]", fontsize = plot_font_size)
_plt.show()
# *** Plot how equivalent widths converges
if False:
for r in regions[:]:
pts = np.arange(3, len(r.wav), step = 1)
ew_lin, ew_quad = ewutils.interp_equivalent_width_for(r, pts)
_plt.plot(pts, ew_lin, color = "red")
_plt.plot(pts, ew_quad, color = "blue")
_plt.tight_layout()
_plt.show()
if False:
for r in regions[:]:
pts = np.arange(3, 200, step = 1)
pts, ew, ew_std = ewutils.equivalent_width_for(r, pts)
_plt.errorbar(pts, ew, yerr = ew_std)
_plt.tight_layout()
_plt.show()
if False:
for r in regions[:]:
skips = np.arange(1, int(len(r.wav)/3), step = 1)
ew = ewutils.equivalent_width_with(r, skips)
_plt.plot(skips, ew)
_plt.tight_layout()
_plt.show()
# *** Check the sensitivity of equivalent widths for lines
if False:
regs = [9, -1]
offsets = [np.linspace(-0.03, 0.03, num = 25), np.linspace(-0.03, 0.03, num = 25)]
for r, off in zip(regs, offsets):
o, ew = ewutils.equivalent_width_ci(regions[r], off)
_plt.plot(o, ew)
_plt.ylim(0,1)
_plt.tight_layout()
_plt.show()
if False:
regs = [9, -1]
offsets = np.linspace(-0.03, 0.3, num = 33)
ew = np.zeros(len(result_ew.region_result), dtype = np.float64)
abunderr = np.zeros(len(result_ew.region_result), dtype = np.float64)
for i, r in enumerate(result_ew.region_result):
best_index, best_ew = ewutils.fit(r.region, offsets, r.wav, r.inten)
# abunderr[i] = np.std(r.abund[best_index])
# abunderr[i] = len(set(best_index))
abunderr[i] = np.std(best_ew)/np.mean(best_ew)
ew[i] = r.obs_eq_width
# ew, abunderr = zip(*sorted(zip(ew, abunderr), key = lambda x: x[0]))
_plt.plot(ew, abunderr, ".")
_plt.tight_layout()
_plt.show()
# ***
if False:
regres = result_chi.region_result
best_abund = result_chi.abund
regres = sorted(regres, key = lambda rr: abs(rr.best_abund - best_abund))
rrspec = {8: 11.11}
for i, r in enumerate(regres):
_plt.title("Nr " + str(i) + " $| \\Delta " + _LOG_ABUND_CONV + " | = " + str(abs(r.best_abund - best_abund)) + "$ (" + _line_id(r.region.lab_wav) + ")")
plot_region(r, obs_pad = rrspec.get(i, 5.75))
# *** Plot the mosaic of the observed lines in the regions
if False:
plot_region_mosaic(regions_sorted, 3, 5, figsize = (6, 5))
# *** Plots the effects of macroturbulance... specifically it shows up the effects of convolving the synthetic spectrum
if False:
plot_macroturb(result_chi.region_result[3], xticks = 5, yticks = [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], figsize = (5, 3))
# *** Plots the effects of shifts and how the chi squared changes with shifts, for a particular region
if False:
pltshift = partial(plot_shifted, xticks = 3, xlim = (5778.41, 5778.49), ylim = (0.67, 0.92))
pltchisq = plot_vs(lambda r: (r.shift_all, r.chisq_all[r.best_index]), xlabel = u"Shift [Å]", ylabel = "$\\chi^2$", xlim = (-0.10, 0.10))
plot_row(result_chi.region_result[5], [pltshift, pltchisq], figsize = (6, 3))
if False:
regres = result_chi.region_result[5]
_plt.figure(figsize = (3, 2.5))
plot_shifted(regres, xticks = 3, xlim = (5778.41, 5778.49), ylim = (0.655, 0.94))
_plt.figure(figsize = (3, 2.5))
plot_vs(lambda r: (r.shift_all, r.chisq_all[r.best_index]), xlabel = u"Shift [Å]", ylabel = "$\\chi^2$", xlim = (-0.10, 0.10))(regres)
# *** Plots several abundances for a region and how chi squared changes with abundance, for that region... the region is the line at approximately 5778 Å
if False:
pltline = partial(plot_region, show_abunds = True, abund_filter = [7, 490], xticks = 3, xlim = (5778.33, 5778.59), ylim = (0.3, 1.1))
pltchisq = plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xlim = (7.2, 7.7), xfmt = "%0.1f")
plot_row(result_chi.region_result[5], [pltline, pltchisq], figsize = (6, 3))
if False:
regres = result_chi.region_result[5]
_plt.figure(figsize = (3, 2.5))
plot_region(regres, show_abunds = True, abund_filter = [7, 490], xticks = 3, xlim = (5778.33, 5778.59))
_plt.figure(figsize = (3, 2.5))
plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xlim = (7.2, 7.7), xfmt = "%0.1f")(regres)
# *** Plots several abundances for a region and how chi squared changes with abundance, for that region... the region is the line at approximately 5232 Å
if False:
pltline = partial(plot_region, show_abunds = True, abund_filter = [7, 490], xlim = (5232.17, 5234.16), xticks = 3)
pltchisq = plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xlim = (7.2, 7.7), xfmt = "%0.1f")
plot_row(result_chi.region_result[-1], [pltline, pltchisq], figsize = (6, 3))
if False:
regres = result_chi.region_result[-1]
_plt.figure(figsize = (3, 2.5))
plot_region(regres, show_abunds = True, abund_filter = [7, 490], xticks = 3, xlim = (5232.17, 5234.35))
_plt.figure(figsize = (3, 2.5))
plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xlim = (7.2, 7.7), xfmt = "%0.1f")(regres)
# *** Plots a close up on what happens for different abundances for the strong line at approximately 5232 Å
if False:
_plt.figure(figsize = (6,3.5))
plot_region(result_chi.region_result[-1], show_abunds = True, abund_filter = [0, 58, 201, 309, 499], xlim = (5232.89, 5233.01), ylim = (0.165, 0.192))
if False:
regres = result_chi.region_result[-1]
_plt.figure(figsize = (3.2, 2.5))
plot_region(regres, show_abunds = True, abund_filter = [7, 490], xticks = 3, xlim = (5232.17, 5234.35))
_plt.figure(figsize = (3.2, 2.5))
plot_region(regres, show_abunds = True, xticks = 3, abund_filter = [0, 58, 201, 309, 499], xlim = (5232.89, 5233.10), ylim = (0.165, 0.192))
# *** Histogram over the distribution of best shifts among the results from the regions
# Using the inbuilt histogram plotting function
if False:
_plt.figure(figsize = (6, 2.8))
_plt.hist([r.best_shift for r in result_chi.region_result], bins = 15)
_plt.xlim(-0.0022, 0.0102)
_plt.xlabel(u"Shift [Å]", fontsize = plot_font_size)
_plt.ylabel("Number of lines", fontsize = plot_font_size)
_plt.tight_layout()
_plt.show()
# Using a custom histogram plotting function
if False:
_plt.figure(figsize = (5, 2.8))
plot_hist([1e3*r.best_shift for r in result_chi.region_result], bin_width = 1, xlabel = u"Shift [mÅ]", ylabel = "Number of lines")
# *** Plot/histogram over the velocities that would give certain shifts
if False:
doppler_vels = [_calc_vel(r.best_shift, r.wav[np.argmin(r.inten[r.best_index])]) for r in result_chi.region_result]
# shifts = [r.best_shift for r in result_chi.region_result]
# linewl = [r.wav[np.argmin(r.inten[r.best_index])] for r in result_chi.region_result]
# doppler_vels, shifts, linewl = zip(*sorted(zip(*[doppler_vels, shifts, linewl]), key = lambda x: x[2]))
_plt.hist(doppler_vels)
_plt.show()
# *** Histogram over the distribution of the absolute value of the difference in equivalent width between the synthetic and observed lines
if False:
_plt.figure(figsize = (5, 2.8))
_plt.hist([1e3*abs(r.best_diff) for r in result_ew.region_result])
_plt.xlabel(u"$| \\Delta W |$ [mÅ]")
_plt.ylabel("Number of lines")
_plt.yticks([0, 1, 2, 3, 4])
_plt.tight_layout()
_plt.show()
# *** Plots histograms over the distributions of abundances for the results obtained using chi squared and equivalent widths
if False:
bins = 10
f, ax = _plt.subplots(1,2, figsize = (6,2.8))
ax[0].hist(_abund(result_chi.best_abunds), bins = bins)
ax[0].set_yticks([0,1,2,3])
ax[0].set_xlim(7.33, 7.55)
ax[0].set_xlabel("$" + _LOG_ABUND_CONV + "$")
ax[0].set_ylabel("Number of lines")
ax[1].hist(_abund(result_ew.best_abunds), bins = bins)
ax[1].set_yticks([0,1,2,3])
ax[1].set_xlim(7.38, 7.65)
ax[1].set_xlabel("$" + _LOG_ABUND_CONV + "$")
ax[1].set_ylabel("Number of lines")
_plt.tight_layout()
_plt.show()
# *** Plots the line at approximately 5323 Å (happens to be the strongest line of the ones that has been used)
if False:
_plt.figure(figsize = (6,3))
plot_region(result_chi.region_result[-1], obs_last = True, xticks = 7)
# *** Plots the line at approximately 5778 Å
if False:
_plt.figure(figsize = (6,3))
plot_region(result_chi.region_result[5], obs_last = True, xticks = 7)
# *** Plots the line at approximately 5705 Å
if False:
_plt.figure(figsize = (6,3))
plot_region(result_chi.region_result[11], obs_last = True, xticks = 7)
# *** Plots the first 8 lines together
# if False:
# plot_mosaic(result_chi.region_result[:8], 4, 2, partial(plot_region, xticks = 3), figsize = (6,9))
# *** Plots the lines (both observed and synthetic) together
if False:
def plotfunc(region_result, figure_axes = None):
#if np.array_equal(region_result.region.wav, result_chi.region_result[-1].region.wav):
if region_result is result_chi.region_result[-1]:
plot_region(region_result, xticks = 3, xlim = (5232.13, 5234.12), figure_axes = figure_axes)
else:
plot_region(region_result, xticks = 3, figure_axes = figure_axes)
rr_chi = sorted(result_chi.region_result, key = lambda r: r.region.lab_wav)
plot_mosaic(rr_chi[:8], 4, 2, plotfunc, figsize = (6,9))
plot_mosaic(rr_chi[8:], 4, 2, plotfunc, figsize = (6,9))
# *** Plots the bisector of the line at approximately 6302 Å (both for the observed and synthetic spectra)
if False:
regres = result_chi.region_result[1]
f, ax = _plt.subplots(nrows = 1, ncols = 2, figsize = (6,3))
plot_bisector(regres.region.wav, regres.region.inten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", figure_axes = ax[0], color = "blue")
plot_bisector(regres.wav, regres.best_inten, xy_args = options(color = "red"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", figure_axes = ax[1], color = "red")
_plt.tight_layout()
_plt.show()
if False:
regres = result_chi.region_result[1]
_plt.figure(figsize = (3,3))
plot_bisect(regres, show_synth = True, xticks = 3)
_plt.figure(figsize = (3,3))
plot_bisector(regres.region.wav, regres.region.inten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (6302.48, 6302.50), ylim = (0.3, 1.0), color = "blue")
# *** Plots the bisector of the line at approximately 6302 Å (only for the observed spectra)
if False:
line_nr = 1
rwav = result_chi.region_result[line_nr].region.wav
rinten = result_chi.region_result[line_nr].region.inten
f, ax = _plt.subplots(nrows = 1, ncols = 2, figsize = (6,3))
plot_bisector(rwav, rinten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (rwav[0], rwav[-1]), ylim = (0.0, 1.1), figure_axes = ax[0], color = "blue")
plot_bisector(rwav, rinten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (6302.48, 6302.50), ylim = (0.3, 1.0), figure_axes = ax[1], color = "blue")
_plt.tight_layout()
_plt.show()
if False:
line_nr = 1
rwav = result_chi.region_result[line_nr].region.wav
rinten = result_chi.region_result[line_nr].region.inten
_plt.figure(figsize = (3,3))
plot_bisector(rwav, rinten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (rwav[0], rwav[-1]), ylim = (0.0, 1.1), color = "blue")
_plt.figure(figsize = (3,3))
plot_bisector(rwav, rinten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (6302.48, 6302.50), ylim = (0.3, 1.0), color = "blue")
# *** Plots the bisector of the line at approximately 6301 Å (both for the observed and synthetic spectra)
if False:
_plt.figure(figsize = (4,3))
plot_bisect(result_chi.region_result[0], show_synth = True, xticks = 5)
if False:
regres = result_chi.region_result[0]
_plt.figure(figsize = (3,3))
plot_bisect(regres, show_synth = True, xticks = 3)
_plt.figure(figsize = (3,3))
plot_bisector(regres.region.wav, regres.region.inten, xy_args = options(color = "blue"), xticks = 3, xlabel = u"Wavelength [Å]", ylabel = "Normalized intensity", xfmt = "%0.2f", xlim = (6301.48, 6301.50), ylim = (0.3, 1.0), color = "blue")
# *** Plots the bisector of line with wavelength approximately 6301 Å (both for the observed and synthetic spectra)
if False:
_plt.figure(figsize = (5,3))
regres = result_chi.region_result[0]
swav = regres.wav
sinten = regres.best_inten
rwav = regres.region.wav
rinten = regres.region.inten
bwav, binten = bisect.get_bisector(swav, sinten, ylim = 0.96)
lbl_synth = _plt.plot(bwav, binten, color = "red", label = _log_abund_str(regres.best_abund))
_plt.plot(swav, sinten, color = "red", linestyle = "--")
bwav, binten = bisect.get_bisector(rwav, rinten, ylim = 0.96)
lbl_obs = _plt.plot(bwav, binten, color = "blue", label = "FTS atlas")
_plt.plot(rwav, rinten, color = "blue", linestyle = "--")
xlim = (max(swav[0], rwav[0]) + 0.04, min(swav[-1], rwav[-1]) - 0.04)
_plt.xlim(xlim)
_plt.ylim(0, 1.1)
_plt.xticks(np.linspace(xlim[0], xlim[1], num = 5))
_plt.gca().xaxis.set_major_formatter(ticker.FormatStrFormatter("%0.2f"))
_plt.legend(handles = [lbl_synth[0], lbl_obs[0]], frameon = False, loc = 4, fontsize = legend_font_size)
_plt.xlabel(u"Wavelength [Å]", fontsize = plot_font_size)
_plt.ylabel("Normalized intensity", fontsize = plot_font_size)
_plt.tight_layout()
_plt.show()
# *** Plots the differences in abundance between when chi squared is used and when equivalent widths are used
if False:
# Calculate the differences in abundance between when chi squared is used and when equivalent widths are used
data_unordered = [(r_chi.region.lab_wav, r_chi.best_abund - r_ew.best_abund) for r_chi, r_ew in zip(result_chi.region_result, result_ew.region_result)]
data_diffs = sorted(data_unordered, key = lambda x: x[0])
rwav, abund_diff = map(np.array, zip(*data_diffs))
# Plot the differences
_plt.figure(figsize = (5, 3))
_plt.plot(rwav, abund_diff, ".")
_plt.xlabel(u"Wavelength [Å]", fontsize = plot_font_size)
_plt.ylabel("$\\Delta " + _LOG_ABUND_CONV + "$", fontsize = plot_font_size)
_plt.xlim(rwav[0] - 50, rwav[-1] + 50)
_plt.xticks(np.linspace(rwav[0], rwav[-1], num = 6))
_plt.tight_layout()
_plt.show()
# *** (NOT USED)
if False:
data_unordered = [(r_ew.obs_eq_width, r_chi.best_abund - r_ew.best_abund) for r_chi, r_ew in zip(result_chi.region_result, result_ew.region_result)]
data_diffs = sorted(data_unordered, key = lambda x: x[0])
ew, abund_diff = map(np.array, zip(*data_diffs))
# Plot the differences
_plt.figure(figsize = (4, 3))
_plt.plot(ew, abund_diff, ".")
_plt.xlabel(u"$EW$ [" + str(result_ew.region_result[0].eq_width_unit) + "]", fontsize = plot_font_size)
_plt.ylabel("$\\Delta " + _LOG_ABUND_CONV + "$", fontsize = plot_font_size)
# _plt.xlim(rwav[0] - 50, rwav[-1] + 50)
# _plt.xticks(np.linspace(rwav[0], rwav[-1], num = 6))
_plt.tight_layout()
_plt.show()
# *** Show the difference in abundance between the best synthetic lines obtained by chi squared and equivalent widths
if False:
# Get the data
data_unordered = [(r_chi.best_abund - r_ew.best_abund, r_chi, r_ew) for r_chi, r_ew in zip(result_chi.region_result, result_ew.region_result)]
abund_diffs, region_result_chi, region_result_ew = zip(*sorted(data_unordered, key = lambda x: x[0]))
# Loop throw a number of lines and plot the best synthetic lines obtained by chi squared and equivalent widths
number_of_lines = 1
offset = 0
show_around = 0
show_unzoomed = False
for ai in range(number_of_lines):
regres_chi = region_result_chi[ai + offset]
regres_ew = region_result_ew[ai + offset]
region = regres_chi.region
# Get the wavelengths to plot
rwav = region.wav
rinten = region.inten
if show_around == 0:
owav = rwav
ointen = rinten
else:
owav, ointen, _ = _at.getatlas(rwav[0] - show_around, rwav[-1] + show_around, cgs = True)
ointen /= region.inten_scale_factor
if show_unzoomed:
rwav = owav
rinten = ointen
# The the minimum and maximum wavelengths
wav_min, wav_max = min([rwav[0], regres_chi.wav[0], regres_ew.wav[0]]), max([rwav[-1], regres_chi.wav[-1], regres_ew.wav[-1]])
inten_min = min([min(ointen), min(regres_chi.best_inten), min(regres_ew.best_inten)])
# Plot the difference
_plt.figure(figsize = (5,3))
#lbl_obs = _plt.plot(owav, ointen, color = "blue", alpha = 0.45, linestyle = "-", label = "FTS atlas")
lbl_obs = _plt.plot(owav, ointen, color = "blue", linestyle = "--", label = "FTS atlas")
lbl_chi = _plt.plot(regres_chi.wav, regres_chi.best_inten, color = "red", label = "$\\chi^2$")
lbl_ew = _plt.plot(regres_ew.wav - regres_chi.best_shift, regres_ew.best_inten, color = "green", label = "$EW$")
legend_labels = [lbl_obs[0], lbl_chi[0], lbl_ew[0]]
_plt.xlim(wav_min, wav_max)
_plt.ylim(max(inten_min - 0.05, 0), 1.05)
_plt.xticks(np.linspace(wav_min, wav_max, num = 5))
_plt.xlabel(u"Wavelength [Å]", fontsize = plot_font_size)
_plt.ylabel("Normalized intensity", fontsize = plot_font_size)
_plt.legend(handles = legend_labels, loc = 4, frameon = False, fontsize = legend_font_size)
_plt.gca().xaxis.set_major_formatter(ticker.FormatStrFormatter("%0.2f"))
_plt.tight_layout()
_plt.show()
# ***
if False:
region_result = result_chi.region_result
plot_row(region_result[14], [partial(plot_region, show_abunds = True, abund_filter = [127, 350, 490], xticks = 4), plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xticks = np.array([7.2 , 7.35, 7.5 , 7.65, 7.8]))], figsize = (7,3.5))
# *** Plots the chi squared of the shifts for all the regions
if False:
for r in result_chi.region_result:
plot_vs(lambda r: (_abund(r.abund), r.chisq), xlabel = "$" + _LOG_ABUND_CONV + "$", ylabel = "$\\chi^2$", xlim = (7.2, 7.7), xfmt = "%0.1f")(r)
def plot_pert(pertubations, results):
results_chi = [r.result_chi for r in results]
results_ew = [r.result_ew for r in results]
regions = [r.region for r in results_chi[0].region_result]
# Sets the currently used results object
# Allows easy switching between results_chi and results_ew
results_curr = results_ew
# *** Show the effects on the abundance of each individual line, together
if False:
_plt.figure(figsize = (6, 3))
lbls = []
for i in range(len(results_curr[0].region_result)):
abunds = [r.region_result[i].best_abund for r in results_curr]
curr_lbl = _plt.plot(pertubations, _abund(abunds), label = "Fe I $\\lambda$ $" + str(results_curr[0].region_result[i].region.lab_wav) + "$")
lbls.append(curr_lbl[0])
_plt.xlabel("Pertubation", fontsize = plot_font_size)
_plt.ylabel("$\\log A$", fontsize = plot_font_size)
_plt.legend(handles = lbls, fontsize = legend_font_size, frameon = False, loc = 4)
_plt.tight_layout()
_plt.show()
# *** Show the effects on the abundance of a single line
if False:
_plt.figure(figsize = (5, 3))
abunds = [r.region_result[0].best_abund for r in results_curr]
# lbl = _plt.plot(pertubations, _abund(abunds), label = "Fe I $\\lambda$ $" + str(results_curr[0].region_result[0].region.lab_wav) + "$")
_plt.plot(pertubations, _abund(abunds))
_plt.xlabel("Pertubation $\\Delta \\log(gf)$", fontsize = plot_font_size)
_plt.ylabel("$\\log A$", fontsize = plot_font_size)
# _plt.xticks(pertubations[::2])
# _plt.legend(handles = [lbl[0]], fontsize = legend_font_size, frameon = False)
_plt.tight_layout()
_plt.show()
# *** Show the effects on the mean abundance
if False:
_plt.figure(figsize = (6, 3))
abunds = [r.abund for r in results_curr]
_plt.plot(pertubations, _abund(abunds))
_plt.xlabel("Pertubation $\\Delta \\log(gf)$", fontsize = plot_font_size)
_plt.ylabel("$\\log A$", fontsize = plot_font_size)
_plt.tight_layout()
_plt.show()
# *** Show the effects on the abundance of a single line, comparing the results obtained through chi squared and equivalent widths
if False:
_plt.figure(figsize = (6, 3))
abunds_chi = [r.region_result[0].best_abund for r in results_chi]
abunds_ew = [r.region_result[0].best_abund for r in results_ew]
lbl_chi = _plt.loglog(pertubations, _abund(abunds_chi), label = "$\\chi^2$")
lbl_ew = _plt.loglog(pertubations, _abund(abunds_ew), label = "$EW$")
_plt.xlabel("Pertubation $\\Delta \\log(gf)$", fontsize = plot_font_size)
_plt.ylabel("$\\log A$", fontsize = plot_font_size)
_plt.legend(handles = [lbl_chi[0], lbl_ew[0]], fontsize = legend_font_size, frameon = False)
_plt.tight_layout()
_plt.show()
def _line_id(lab_wav):
return "Fe I $\\lambda$ ${:0.4f}$".format(lab_wav)
def _calc_vel(delta_lambda, lambda_em):
"""
Calculates the velocity that corresponds to a doppler shift
with a given shift delta_lambda and an emitted wavelength lambda_em.
"""
return delta_lambda*300000.0/lambda_em
# Get the atlas
_at = _sa.satlas()
# A list of colors to use in plots
plot_color_list = ["#AA0000", "#008800", "#AA00AA",
"#519A2A", "#AAAA00", "#00AAAA",
"#AF009F", "#0F3FF0", "#F0F50F",
"#A98765", "#0152A3", "#0FAAF0",
"#C0110C", "#0B0D0E", "#BDC0EB"]
# Set the font size of the plots
plot_font_size = 11
title_font_size = plot_font_size
legend_font_size = 8
# Set the font to the default
def init_plot_font():
print("\n\n*************** Setting font ***************")
_plt.rc("font", **{"family": u"sans-serif", u"sans-serif": [u"Helvetica"], "size": plot_font_size})
_plt.rc("text", usetex = True)
_plt.rc("text.latex", **{"preamble": [u"\\usepackage{helvet}\\usepackage{sfmath}"], "unicode": True})
# _plt.rc("text.latex", **{"preamble": [u"\\usepackage{helvet}\\usepackage{sfmath}"], "unicode": True})
# _plt.rcParams.update({"font.size": plot_font_size})
print("*************** Font set ***************\n\n")
#matplotlib.rc("font", **{u"sans-serif": [u"Arial"], u"style": u"normal", u"family": u"sans", u"size": plot_font_size})
#matplotlib.rc("font", **{u"sans-serif": [u"Helvetica"], u"style": u"normal", u"family": u"sans", u"size": plot_font_size})
#matplotlib.rc("text", usetex = True)
#matplotlib.rc("text.latex", **{"preamble": [u"\\usepackage{helvet}\\usepackage{sfmath}"], "unicode": True})
#matplotlib.rcParams["text.latex.unicode"] = True
init_plot_font()
# The figure size (in inches) of some functions
plot_figure_size = (7, 7)
# Determines the notation used for the abundance
_LOG_ABUND_CONV = "\\log A"
def _log_abund_str(value):
"""
Returns a string stating what the abundance is
"""
# value = "{:0.3f}".format(value)
value = str(_abund(value))
return "$" + _LOG_ABUND_CONV + "=" + value + "$"
def estimate_minimum(wav, inten, num = 1000):
"""
Estimates the minimum intensity using quadratic interpolation. The optional argument is
num : The number of points to use when estimating the minimum.
Default is 1000.
"""
tck = si.splrep(wav, inten)
wav = np.linspace(wav[0], wav[-1], num = 1000)
inten = si.splev(wav, tck)
return wav[inten == min(inten)][0]
def _calc_ticks(ticks, values):
if isinstance(ticks, int):
ticks = np.linspace(min(values), max(values), num = ticks)
elif hasattr(ticks, "__call__"):
ticks = ticks(values)
return ticks
def _abund(abund):
"""
Determines the convension for abundance numbers
"""
if isinstance(abund, list):
abund = np.array(abund)
return 12.0 + abund
def partial(func, *args, **kwargs):
"""
Partially applies the given function
"""
def partial_application(*args2, **kwargs2):
argums = args + args2
keywargs = kwargs.copy()
keywargs.update(kwargs2)
return func(*argums, **keywargs)
return partial_application
def figured(plotting_func, *fig_args, **fig_kwargs):
"""
Returns a function that creates a figure with the given arguments and then calls
the given plotting functions. The required argument is
plotting_func : A function that plots something.
All other arguments to this functions are arguments to the figure, specifically they
are passed on to matplotlib.pyplot.figure.
Any arguments given to the returned function are passed on to plotting_func.
"""
def plotter(*args, **kwargs):
_plt.figure(*fig_args, **fig_kwargs)
plotting_func(*args, **kwargs)
return plotter
def _set_title(ax, title):
"""
Sets the title, and makes sure the font size is correct
"""
ax.set_title(title, fontsize = title_font_size)
def options(*args, **kwargs):
return args, kwargs
def _get_figure_axes(figure_axes):
"""
Gets the axis object used to plot stuff. Specifically, if figure_axes is None the current
axis object will be returned. Otherwise, figure_axes will be returned.
"""
if figure_axes is None:
figure_axes = _plt.gca()
return figure_axes
def _adjust_ticks(setter, ax, ticks, curr_ticks, limits, error_message):
if isinstance(ticks, int) and ticks > 0:
if limits is None:
limits = (curr_ticks[0], curr_ticks[-1])
setter(np.linspace(limits[0], limits[1], num = ticks))
elif hasattr(ticks, "__call__"):
if limits is not None:
curr_ticks = curr_ticks[(limits[0] <= curr_ticks) & (curr_ticks <= limits[1])]
setter(ticks(curr_ticks))
elif ticks is not None:
try:
setter(ticks)
except:
raise Exception(error_message(ticks))
def _adjust_xyticks(ax, xticks, yticks, xlimits = None, ylimits = None):
_adjust_ticks(ax.set_xticks, ax, xticks, ax.get_xticks(), xlimits, lambda ticks: "Illegal value for argument 'xticks'. It must be None, a positive integer, a function or a list of xticks to use, but it had type " + type(ticks).__name__ + " and value " + str(ticks))
_adjust_ticks(ax.set_yticks, ax, yticks, ax.get_yticks(), ylimits, lambda ticks: "Illegal value for argument 'yticks'. It must be None, a positive integer, a function or a list of yticks to use, but it had type " + type(ticks).__name__ + " and value " + str(ticks))
def _filter_abund(abund_filter, abund, inten):
"""
Filters out the intensities using the given abundance filter abund_filter, the abundencies abund and
the intensities inten (which is an array of 2 dimensions, for which the rows represent abundencies and
the columns the corresponding values for the intensity). A new numpy array of the same format as inten
is returned.
"""
# Filter out abundances
if abund_filter is not None:
if hasattr(abund_filter, "__call__"):
filtered = np.array([[a, i] for ai, (a, i) in enumerate(zip(abund, inten)) if abund_filter(ai, a, i)])
abund = filtered[:,0]
inten = filtered[:,1]
else:
abund = abund[abund_filter]
inten = inten[abund_filter]
return abund, inten
def plot_bisector(x, y, num = 50, xticks = None, yticks = None, xlim = None, ylim = None, blim = None, xlabel = None, ylabel = None, xfmt = None, yfmt = None, plot_values = True, xy_args = None, show = True, figure_axes = None, **kwargs):
"""
Plots a bisector given by x and y. Required arguments
x : The x values.
y : The y values.
The optional arguments are
num : The number of points in the bisector.
Default is 50.
xticks : Sets the ticks of the x axis. It can be None, an integer or a function. If this is an integer, it specifies how many
ticks should be used. If, on the other hand, this is a function then it will take the array of x values and return a new
array of filtered ticks. And if None is used, nothing will happen.
Default is None.
yticks : Sets the ticks of the y axis. It can be None, an integer or a function. If this is an integer, it specifies how many
ticks should be used. If, on the other hand, this is a function then it will take the array of y values and return a new
array of filtered ticks. And if None is used, nothing will happen.
Default is None.
xlim : Sets the limits of the x axis. Should either be a 2 element tuple or None. If None, no limit will be placed. Otherwise
the first element in the tuple is the minimum x value shown and the second element is the maximum x value shown.
Default is None.
ylim : Sets the limits of the y axis. Should either be a 2 element tuple or None. If None, no limit will be placed. Otherwise
the first element in the tuple is the minimum y value shown and the second element is the maximum y value shown.
Default is None.
blim : Sets the upper limit of the bisectors y values. If set to None, no such limit is used. Otherwise, blim has to be a number
or a function. If it is a function it will accept the y values and return a number that will be used as the y limit.
Default is None.
xlabel : If not None, sets the label of the x axis.
Default is None.
ylabel : If not None, sets the label of the y axis.
Default is None.
xfmt : If not None, sets how the numbers on the x axis are formatted. This is expected to be a string that is given to a
matplotlib.ticker.FormatStrFormatter object. See matplotlib.ticker.FormatStrFormatter for more information about how this
works.
Default is None.
yfmt : If not None, sets how the numbers on the y axis are formatted. This is expected to be a string that is given to a
matplotlib.ticker.FormatStrFormatter object. See matplotlib.ticker.FormatStrFormatter for more information about how this
works.
Default is None.
plot_values : Determines if the x and y values should be plotted as well as the bisector. True means they are plotted, False that they
are not.
Default is True.
xy_args : If not None, this contains the arguments for the plot of the values. Specifically it is a tuple with 2 elements. The first
element is a list and the second a dict. These are the arguments passed on to the function call that plots the x and y values,
if plot_values is set to True. If plot_values is False, this argument does nothing.
Default is None.
show : Determines, assuming figure_axes is None, if the plot should be shown directly. If figure_axes is None, the plot is never
shown directly.
Default is True.
figure_axes : Sets the axes object. If this is None, then the result of matplotlib.pyplot.gca() will be used. And if this is not None
then it will be used to plot the abundance. Also note that if this is not None, the plot will not be shown implicitly. Thereby
this can be used to have several plots in the same figure.
Default is None.
Any additional keyword arguments are passed on to matplotlib.pyplot.plot.
By default, if the plot_values is True, then the plotted x and y values will have the line style "--". This can be set using the xy_args argument.
The return value is a list of the lines that where added.
"""
# If no axes object was given, get the current one from _plt
if figure_axes is None:
ax = _plt.gca()
else:
ax = figure_axes
# Plot the bisector
bx, by = bisect.get_bisector(x, y, ylim = blim, num = num)
if plot_values:
if xy_args is not None:
args_vals, kwargs_vals = xy_args
if "linestyle" not in kwargs_vals:
kwargs_vals["linestyle"] = "--"
plotted = ax.plot(x, y, *args_vals, **kwargs_vals)
else:
plotted = ax.plot(x, y, linestyle = "--")
plotted_bisect = ax.plot(bx, by, **kwargs)
plotted.extend(plotted_bisect)
else:
plotted = ax.plot(bx, by, **kwargs)
# Set the formattings of the x and y axis
if xfmt is not None:
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(xfmt))
if yfmt is not None:
ax.yaxis.set_major_formatter(ticker.FormatStrFormatter(yfmt))
# Make sure there are always limits
if xlim is None:
xlim = (min(x), max(x))
if ylim is None:
ylim = (min(y) - 0.05, 1.1)
# Adjust the ticks for the x and y axes
_adjust_xyticks(ax, xticks, yticks, xlimits = xlim, ylimits = ylim)
# Set the limits and labels
ax.set_xlim(xlim)
ax.set_ylim(ylim)
if xlabel is not None:
ax.set_xlabel(xlabel)
if ylabel is not None:
ax.set_ylabel(ylabel)
# If show is true and no axis object was given, show the plot
if show and figure_axes is None:
_plt.tight_layout()
_plt.show()
# Return the plotted lines
return plotted
def plot_compared(region_result, show_labels = True, abund_filter = None, figure_axes = None):
"""
"""
# Get the axes object
ax = _get_figure_axes(figure_axes)
wav = region_result.region.wav
intensities = _filter_abund(abund_filter, region_result.abund, region_result.inten)
for a, inten in enumerate(intensities):
if not np.all(inten == region_result.best_inten):
ax.plot(wav, inten, color = plot_color_list[a % len(plot_color_list)], alpha = 0.5)
ax.plot(wav, region_result.best_inten, color = "red")
ax.plot(wav, region_result.region.inten, color = "blue")
if show_labels:
ax.set_xlabel(u"Wavelength $\\lambda$ [Å]", fontsize = plot_font_size)
ax.set_ylabel("Normalized intensity", fontsize = plot_font_size)
if figure_axes is None:
_plt.show()
def plot_abund_compared(region_result, abund = None, show_labels = True, show_legend = True, legend_pos = 4, figure_axes = None):
"""
"""
# Get the axes object
ax = _get_figure_axes(figure_axes)
if abund is None:
abund = region_result.best_index
obs_wav = region_result.region.wav
synth_wav = region_result.wav
inten = region_result.inten[abund]
lbl_comp = ax.plot(obs_wav, inten, color = "red", label = "Comp")
lbl_real = ax.plot(synth_wav, inten, color = "red", linestyle = "--", label = "Real")
lbl_obs = ax.plot(obs_wav, region_result.region.inten, color = "blue", label = "Obs")
if show_legend:
ax.legend(handles = [lbl_comp[0], lbl_real[0], lbl_obs[0]], loc = legend_pos, fontsize = legend_font_size, frameon = False)
if show_labels:
ax.set_xlabel(u"Wavelength $\\lambda$ [Å]", fontsize = plot_font_size)
ax.set_ylabel("Normalized intensity", fontsize = plot_font_size)
if figure_axes is None:
_plt.show()
def plot_abund_compared2(region_result, linear_interp = False, abund = None, show_labels = True, show_legend = True, legend_pos = 4, figure_axes = None):
"""
"""
# Get the axes object
ax = _get_figure_axes(figure_axes)
if abund is None:
abund = region_result.best_index
obs_wav = region_result.region.wav
synth_wav = region_result.wav
inten_real = region_result.inten[abund]
if linear_interp:
inten_interp = np.interp(obs_wav, synth_wav, inten_real)
else:
tck = si.splrep(synth_wav, inten_real)
inten_interp = si.splev(obs_wav, tck, der = 0)
lbl_comp = ax.plot(obs_wav, inten_interp, color = "red", label = "Comp")
lbl_real = ax.plot(synth_wav, inten_real, color = "red", linestyle = "--", label = "Real")
lbl_obs = ax.plot(obs_wav, region_result.region.inten, color = "blue", label = "Obs")
if show_legend:
ax.legend(handles = [lbl_comp[0], lbl_real[0], lbl_obs[0]], loc = legend_pos, fontsize = legend_font_size, frameon = False)
if show_labels:
ax.set_xlabel(u"Wavelength $\\lambda$ [Å]", fontsize = plot_font_size)
ax.set_ylabel("Normalized intensity", fontsize = plot_font_size)
if figure_axes is None:
_plt.show()
def plot_shifted(region_result, show_labels = True, show_legend = True, legend_pos = 4, obs_pad = 0.0, abund_filter = None, xlim = None, ylim = None, xticks = None, yticks = None, figure_axes = None):
"""
"""
# Get the axes object
ax = _get_figure_axes(figure_axes)
# Get the wavelengths
wav = region_result.wav
# Make sure entire y scale is shown
# ax.set_xlim([wav[0], wav[-1]])
# ax.set_ylim([0, 1.1])
# Plot the unshifted, shifted and observed spectrums
lbl_obs = ax.plot(region_result.region.wav, region_result.region.inten, color = "blue", label = "FTS atlas")
lbl_best = ax.plot(wav, region_result.best_inten, color = "red", label = "Shifted")
lbl_shifted = ax.plot(wav + region_result.best_shift, region_result.best_inten, color = "red", linestyle = "--", label = "Original")
# Set the formatter
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter("%0.2f"))
# Make sure there are always limits
if xlim is None:
xlim = (min(wav[0], region_result.region.wav[0]), max(wav[-1], region_result.region.wav[-1]))
if ylim is None:
ylim = (0.0, 1.1)
# Adjust the x ticks
_adjust_xyticks(ax, xticks, yticks, xlimits = xlim, ylimits = ylim)
ax.set_xlim(xlim)
ax.set_ylim(ylim)
if show_labels:
ax.set_xlabel(u"Wavelength $\\lambda$ [Å]", fontsize = plot_font_size)
ax.set_ylabel("Normalized intensity", fontsize = plot_font_size)
if show_legend:
ax.legend(handles = [lbl_best[0], lbl_shifted[0], lbl_obs[0]], loc = legend_pos, fontsize = legend_font_size, frameon = False)
if figure_axes is None:
_plt.tight_layout()
_plt.show()
def _create_bins(values, delta):
bins = []
bin_content = set()
# Loop through each value
for v in values:
# If the value has not already been added to the bins...
if v not in bin_content:
# Add the value to the bins
bins.append(v)
bin_content.add(v)
# Add any other value that is close enough and not already in the bins to the bins
for val in values:
if val not in bin_content and abs(v - val) <= delta:
bin_content.add(v)
return bins
def plot_hist(values, delta = 0.0, bins = None, bin_width = None, bin_comparator = None, xlabel = None, ylabel = None, xticks = None, yticks = None, figure_axes = None):
"""
Plots a histogram. The required argument is
values : The values to plot.
The optional arguments are
delta : Determines how far away two values can be while being in the same bin.
Default is 0.
bins : If not None, sets the bins in which to place the different values.
Default is None.
bin_width : If not None, sets the width of the bars in the histogram. Can be a number or a function. If it is a function it takes
a single required argument, which is the bins. If None, the width of the bins will be calculated internally instead.
Default is None.
xlabel : The label for the y axis. If set to None, no such label is shown.
Default is None.
ylabel : The label for the y axis. If set to None, no such label is shown.
Default is None.
xticks : Sets the ticks of the x axis. It can be None, an integer or a function. If this is an integer, it specifies how many
ticks should be used. If, on the other hand, this is a function then it will take the array of x values and return a new
array of filtered ticks. And if None is used, nothing will happen.
Default is None.
yticks : Sets the ticks of the y axis. It can be None, an integer or a function. If this is an integer, it specifies how many
ticks should be used. If, on the other hand, this is a function then it will take the array of y values and return a new
array of filtered ticks. And if None is used, nothing will happen.
Default is None.
figure_axes : Sets the axes object. If this is None, then the result of
matplotlib.pyplot.gca() will be used. And if this is not None
then it will be used to plot the abundance. Also note that
if this is not None, the plot will not be shown implicitly.
Thereby this can be used to have several plots in the same figure.
Default is None.
"""
if len(values) == 0:
raise Exception("Need at least 1 value, but 'values' was empty.")
ax = _get_figure_axes(figure_axes)
if bins is None:
bins = _create_bins(values, delta)
content = np.zeros(len(bins), dtype = np.float64)
for i, b in enumerate(bins):
for v in values:
if abs(v - b) <= delta:
content[i] += 1
bin_data = sorted(zip(bins, content), cmp = bin_comparator, key = lambda bd: bd[0])
bins, content = map(np.array, zip(*bin_data))
# Set the bin width
if bin_width is None:
bin_width = min(bins[1:] - bins[:-1]) if len(bins) > 1 else 1
elif hasattr(bin_width, "__call__"):
bin_width = bin_width(bins)
# Plot the bars
for b, c in bin_data:
ax.bar(b - bin_width/2.0, c, width = bin_width, bottom = 0)
ax.set_xlim(bins[0] - 3.0*bin_width/4.0, bins[-1] + 3.0*bin_width/4.0)
ax.set_ylim(0, max(content))
if xticks is not None:
ax.set_xticks(_calc_ticks(ticks))
if yticks is not None:
ax.set_yticks(_calc_ticks(ticks))
if xlabel is not None:
ax.set_xlabel(xlabel, fontsize = plot_font_size)
if ylabel is not None:
ax.set_ylabel(ylabel, fontsize = plot_font_size)
if figure_axes is None:
_plt.tight_layout()
_plt.show()