Skip to content

Commit 890e6d9

Browse files
Add histogram plot type
1 parent ef886b1 commit 890e6d9

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ set(FPLOT_SOURCES
4242
${dir}/fplot_plot_data_3d.f90
4343
${dir}/fplot_surface_plot_data.f90
4444
${dir}/fplot_stats_plots.f90
45+
${dir}/fplot_plot_histogram.f90
4546
)
4647
set(FPLOT_SOURCES ${FPLOT_SOURCES} PARENT_SCOPE)

src/fplot_plot_histogram.f90

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module fplot_plot_histogram
2+
use iso_fortran_env
3+
use fplot_plot_bar
4+
use fplot_plot_data
5+
use fplot_plot_data_histogram
6+
use strings
7+
implicit none
8+
private
9+
10+
type, extends(plot_bar) :: plot_histogram
11+
!! Defines a 2D plot tailored towards histogram plotting.
12+
contains
13+
end type
14+
contains
15+
! ------------------------------------------------------------------------------
16+
function ph_get_cmd(this) result(rst)
17+
!! Gets the GNUPLOT commands required to draw the plot.
18+
class(plot_histogram), intent(in) :: this
19+
!! The plot_histogram object.
20+
character(len = :), allocatable :: rst
21+
!! The command string.
22+
23+
! Local Variables
24+
integer(int32) :: i, n
25+
real(real64) :: minX, maxX
26+
type(string_builder) :: str
27+
class(plot_data), pointer :: pd
28+
29+
! Cycle over the data and determine the min and max values from the data
30+
n = this%get_count()
31+
maxX = -huge(1.0d0)
32+
minX = huge(1.0d0)
33+
do i = 1, n
34+
pd => this%get(i)
35+
if (.not.associated(pd)) cycle
36+
select type (pd)
37+
class is (plot_data_histogram)
38+
maxX = max(maxX, pd%get_maximum_value())
39+
minX = min(minX, pd%get_minimum_value())
40+
end select
41+
end do
42+
43+
! Define the x axis tic labels
44+
45+
! Call the base method
46+
call str%append(this%plot_bar%get_command_string())
47+
48+
! End
49+
rst = str%to_string()
50+
end function
51+
52+
! ------------------------------------------------------------------------------
53+
end module

0 commit comments

Comments
 (0)