This is an answer to the last question ASHAN recently asked.
As this answer goes beyond the simple example supplied by ASHAN in that it extends the possibilities of Statistics:-ColumnGraph, I thought it would be appropriate to share it with the entire community of Maple users.

Possible improvements:

  • add controls for parameter types
  • add consistency controls (numer of colors = number of data rows for instance)
  • add some custom parameters
  • improve legend position
     

restart

CustomColumnGraph := proc(
                       data
                       , BarColors
                       , GroupTitles
                       , BarWidth         
                       , GroupOffset      
                       , LegendBarHeight
                       , VerticalShiftFactor
                       , BarFont
                       , GroupFont
                       , LegendFont
                       , BarTitleFormat
                     )



  local Ni, Nj, W, DX, LH, LW, SF, L, DL:

  local SingleBar := (w, h, c) -> rectangle([0, 0], [w, h], color=c):
  local BarGraph, Legends:

  uses plots, plottools:

  Ni := numelems(data[..,1]):
  Nj := numelems(data[1]):
  W  := BarWidth:
  DX := GroupOffset:
  LH := LegendBarHeight:
  SF := VerticalShiftFactor;
  L  := DX*(Ni-1) + W*(Nj-1) + DX/2 + DX/4:
  LW := L / Ni / Nj / 2;                          # LegendBarWidth  
  DL := solve(dl*(Nj+1) + Nj*(3*LW) = L, dl);



  BarGraph := display(
                seq(
                  seq(
                    translate(SingleBar(W, data[i, j], BarColors[j]), DX/4 + DX*(i-1) + W*(j-1), 0)
                    , i=1..Ni
                  )
                  , j=1..Nj
                )
                , axis[1] = [gridlines = [], tickmarks = []]
                , axis[2] = [gridlines = [11, linestyle = dot, thickness = 0, color = "LimeGreen"]]
              ):

  Legends := display(
               seq(
                 translate(SingleBar(LW, LH, BarColors[j]), DL/2 + LW + (3*LW+DL)*(j-1), min(data)*(2*SF-1))
                 , j=1..Nj
               )
               ,
               seq(
                 translate(
                   textplot([0, LH/2, GroupTitles[j]], align=right, font = LegendFont)
                   , DL/2 + 2*LW + (3*LW+DL)*(j-1), min(data)*1.4)
                   , j=1..Nj
               )
             ):

  display(
    BarGraph  
    , Legends

    #------------------------------- X base line
    , plot(0, x=0..DX*(Ni-1)+W*(Nj-1)+DX/2 + DX/4)
 
    #------------------------------- Left bar group boundaries
    ,
    seq(
      line(
        [DX/4 + DX*(i-1) - W/2, min(data)*SF],
        [DX/4 + DX*(i-1) - W/2, max(data)*SF]
        , color="LightGray"
      )
      , i=1..Ni
    )


    #------------------------------- Right bar group boundaries
    ,
    seq(
      line(
        [DX/4 + DX*(i-1) + W*Nj + W/2, min(data)*SF],
        [DX/4 + DX*(i-1) + W*Nj + W/2, max(data)*SF]
        , color="LightGray"
      )
      , i=1..Ni
    )
  
    #------------------------------- Top bar group boundaries
    ,
    seq(
      line(
        [DX/4 + DX*(i-1) - W/2, max(data)*SF],
        [DX/4 + DX*(i-1) + W*Nj + W/2, max(data)*SF]
        , color="LightGray"
      )
      , i=1..Ni
    )
 
    #------------------------------- Bar titles
    ,
    seq(
      seq(
        textplot(
          # [DX/4 + DX*(i-1) + W*(j-1) +W/2, data[i, j], evalf[3](data[i, j])]
          [DX/4 + DX*(i-1) + W*(j-1) +W/2, data[i, j], sprintf(BarTitleFormat, data[i, j])]
          , font=BarFont
          , align=`if`(data[i, j] > 0, above, below)
        )
        , i=1..Ni
      )
      , j=1..Nj
    )
  
    #------------------------------- Bar group titles
    ,
    seq(
      textplot(
        [DX/4 + DX*(i-1) + W*(Nj/2), max(data)*SF, cat("B", i)]
        , font=GroupFont
        , align=above
      )
      , i=1..Ni
    )
  
    , labels=["", ""]
    , size=[800, 400]
    , view=[0..DX*(Ni-1) + W*(Nj-1) + DX/2 + DX/4, default]
  );
end proc:

 

Data from  AHSAN

 

A := [0.1, 0.5, 0.9]:
B := [0.5, 2.5, 4.5]:


Nu_A := [-0.013697, 0.002005, 0.017707, -0.013697, 0.002005, 0.017707, -0.013697, 0.002005, 0.017707]:
Nu_B := [0.010827, 0.011741, 0.012655, 0.013967, 0.014881, 0.015795, 0.017107, 0.018021, 0.018935]:


i:=4:
data := Matrix([[Nu_A[i], Nu_B[i]], [Nu_A[i + 1], Nu_B[i + 1]], [Nu_A[i + 2], Nu_B[i + 2]]]):
 

 

Column Graph

 

Ni, Nj := LinearAlgebra:-Dimensions(data):

CustomColumnGraph(
                   data                                        # data
                   , ["Salmon", "LightGreen"]                  # BarColors
                   , ["Sensitivity to A", "Sensitivity to B"]  # GroupTitles
                   , 1/(numelems(data[1])+2)                   # BarWidth  
                   , 1                                         # GroupOffset  
                   , max(abs~(data))/10                        # LegendBarHeight
                   , 1.2                                       # VerticalShiftFactor
                   , [Tahoma, bold, 10]                        # BarFont
                   , [Tahoma, bold, 14]                        # GroupFont
                   , [Tahoma, bold, 12]                        # LegendFont
                   , "%1.5f"                                   # BarTitleFormat
                 )

 

 

Column Graph of an extended set of data

 

 

ExtentedData := < data | Statistics:-Mean(data^+)^+ >:
ExtentedData := < ExtentedData, Statistics:-Mean(ExtentedData) >:

interface(displayprecision=6):
data, ExtentedData;

Ni, Nj := LinearAlgebra:-Dimensions(ExtentedData):


CustomColumnGraph(
                   ExtentedData                                  
                   , ["Salmon", "LightGreen", "Moccasin"]                 
                   , ["Sensitivity to A", "Sensitivity to B", "Mean Sensitivity to A and B"]
                   , 1/(numelems(data[1])+2)                   # BarWidth  
                   , 1                                         # GroupOffset  
                   , max(abs~(data))/10                        # LegendBarHeight
                   , 1.2                                       # VerticalShiftFactor
                   , [Tahoma, 10]                              # BarFont
                   , [Tahoma, bold, 14]                        # GroupFont
                   , [Tahoma, 12]                              # LegendFont
                   , "%1.3f"                                   # BarTitleFormat
                 )

Matrix(3, 2, {(1, 1) = -0.13697e-1, (1, 2) = 0.13967e-1, (2, 1) = 0.2005e-2, (2, 2) = 0.14881e-1, (3, 1) = 0.17707e-1, (3, 2) = 0.15795e-1}), Matrix(4, 3, {(1, 1) = -0.13697e-1, (1, 2) = 0.13967e-1, (1, 3) = HFloat(1.349999999999997e-4), (2, 1) = 0.2005e-2, (2, 2) = 0.14881e-1, (2, 3) = HFloat(0.008442999999999999), (3, 1) = 0.17707e-1, (3, 2) = 0.15795e-1, (3, 3) = HFloat(0.016751000000000002), (4, 1) = HFloat(0.002005), (4, 2) = HFloat(0.014881), (4, 3) = HFloat(0.008443)})

 

 

 

 


 

Download CustomColumnGraph.mw

 


Please Wait...