@@ -223,7 +223,7 @@ end subroutine initialize
223
223
!
224
224
! Add an x,y plot.
225
225
226
- subroutine add_plot (me , x , y , label , linestyle , markersize , linewidth )
226
+ subroutine add_plot (me , x , y , label , linestyle , markersize , linewidth , xlim , ylim )
227
227
228
228
class(pyplot), intent (inout ) :: me ! ! pyplot handler
229
229
real (wp), dimension (:), intent (in ) :: x ! ! x values
@@ -232,16 +232,24 @@ subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth)
232
232
character (len=* ), intent (in ) :: linestyle ! ! style of the plot line
233
233
integer , intent (in ), optional :: markersize ! ! size of the plot markers
234
234
integer , intent (in ), optional :: linewidth ! ! width of the plot line
235
+ real (wp),dimension (2 ), intent (in ), optional :: xlim ! ! x-axis range
236
+ real (wp),dimension (2 ), intent (in ), optional :: ylim ! ! y-axis range
235
237
236
- character (len= :), allocatable :: xstr ! ! x values strinfied
237
- character (len= :), allocatable :: ystr ! ! y values strinfied
238
+ character (len= :), allocatable :: xstr ! ! x values stringified
239
+ character (len= :), allocatable :: ystr ! ! y values stringified
240
+ character (len= :), allocatable :: xlimstr ! ! xlim values stringified
241
+ character (len= :), allocatable :: ylimstr ! ! ylim values stringified
238
242
character (len= max_int_len) :: imark ! ! actual markers size
239
243
character (len= max_int_len) :: iline ! ! actual line width
240
244
character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
241
245
character (len=* ), parameter :: yname = ' y' ! ! y variable name for script
242
246
243
247
if (allocated (me% str)) then
244
248
249
+ ! axis limits (optional):
250
+ if (present (xlim)) call vec_to_string(xlim, xlimstr, me% use_numpy)
251
+ if (present (ylim)) call vec_to_string(ylim, ylimstr, me% use_numpy)
252
+
245
253
! convert the arrays to strings:
246
254
call vec_to_string(x, xstr, me% use_numpy)
247
255
call vec_to_string(y, ystr, me% use_numpy)
@@ -263,6 +271,11 @@ subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth)
263
271
' linewidth=' // trim (adjustl (iline))// ' ,' // &
264
272
' markersize=' // trim (adjustl (imark))// ' ,' // &
265
273
' label="' // trim (label)// ' ")' )
274
+
275
+ ! axis limits:
276
+ if (allocated (xlimstr)) call me% add_str(' ax.set_xlim(' // xlimstr// ' )' )
277
+ if (allocated (ylimstr)) call me% add_str(' ax.set_ylim(' // ylimstr// ' )' )
278
+
266
279
call me% add_str(' ' )
267
280
268
281
else
@@ -414,7 +427,7 @@ end subroutine add_3d_plot
414
427
!
415
428
! Add a bar plot.
416
429
417
- subroutine add_bar (me , left , height , label , width , bottom , color , yerr )
430
+ subroutine add_bar (me , left , height , label , width , bottom , color , yerr , align , xlim , ylim )
418
431
419
432
class(pyplot), intent (inout ) :: me ! ! pyplot handler
420
433
real (wp), dimension (:), intent (in ) :: left ! ! left bar values
@@ -424,9 +437,14 @@ subroutine add_bar(me, left, height, label, width, bottom, color, yerr)
424
437
real (wp), dimension (:), intent (in ), optional :: bottom ! ! bottom values
425
438
character (len=* ), intent (in ), optional :: color ! ! plot color
426
439
real (wp), dimension (:), intent (in ), optional :: yerr ! ! yerr values
440
+ character (len=* ), intent (in ), optional :: align ! ! default: 'center'
441
+ real (wp),dimension (2 ), intent (in ), optional :: xlim ! ! x-axis range
442
+ real (wp),dimension (2 ), intent (in ), optional :: ylim ! ! y-axis range
427
443
428
444
character (len= :), allocatable :: xstr ! ! x axis values stringified
429
445
character (len= :), allocatable :: ystr ! ! y axis values stringified
446
+ character (len= :), allocatable :: xlimstr ! ! xlim values stringified
447
+ character (len= :), allocatable :: ylimstr ! ! ylim values stringified
430
448
character (len= :), allocatable :: wstr ! ! width values stringified
431
449
character (len= :), allocatable :: bstr ! ! bottom values stringified
432
450
character (len= :), allocatable :: plt_str ! ! plot string
@@ -439,6 +457,10 @@ subroutine add_bar(me, left, height, label, width, bottom, color, yerr)
439
457
440
458
if (allocated (me% str)) then
441
459
460
+ ! axis limits (optional):
461
+ if (present (xlim)) call vec_to_string(xlim, xlimstr, me% use_numpy)
462
+ if (present (ylim)) call vec_to_string(ylim, ylimstr, me% use_numpy)
463
+
442
464
! convert the arrays to strings:
443
465
call vec_to_string(left, xstr, me% use_numpy)
444
466
call vec_to_string(height, ystr, me% use_numpy)
@@ -462,10 +484,16 @@ subroutine add_bar(me, left, height, label, width, bottom, color, yerr)
462
484
if (present (width)) plt_str= plt_str// ' width=' // trim (wname)// ' ,'
463
485
if (present (bottom)) plt_str= plt_str// ' bottom=' // trim (bstr)// ' ,'
464
486
if (present (color)) plt_str= plt_str// ' color="' // trim (color)// ' ",'
487
+ if (present (align)) plt_str= plt_str// ' align="' // trim (align)// ' ",'
465
488
plt_str= plt_str// ' label="' // trim (label)// ' ")'
466
489
467
490
! write the plot statement:
468
491
call me% add_str(plt_str)
492
+
493
+ ! axis limits:
494
+ if (allocated (xlimstr)) call me% add_str(' ax.set_xlim(' // xlimstr// ' )' )
495
+ if (allocated (ylimstr)) call me% add_str(' ax.set_ylim(' // ylimstr// ' )' )
496
+
469
497
call me% add_str(' ' )
470
498
471
499
else
0 commit comments