Skip to content

Add histogram plotting support #49

@krystophny

Description

@krystophny

Feature Request: Histogram Plotting Support

Description

Add support for histogram plotting to visualize frequency distributions of data. This is one of the most fundamental statistical plot types missing from fortplotlib.

Proposed API

call fig%hist(data, bins=10, label='Data distribution')
call fig%hist(data, bins=[0.0, 1.0, 2.0, 5.0, 10.0])  \! Custom bin edges
call fig%hist(data, bins=20, density=.true.)  \! Probability density

Requirements

  • Support for automatic binning (specify number of bins)
  • Support for custom bin edges
  • Optional density normalization
  • Integration with existing color/label/legend system
  • Support for all backends (PNG, PDF, ASCII)

Implementation Notes

  • Should follow matplotlib's hist() API where possible
  • Need efficient binning algorithm for large datasets
  • Consider cumulative histogram option
  • Handle edge cases (empty data, single value, etc.)

Test Requirements

  • Comprehensive test coverage required
    • Test automatic binning with various bin counts
    • Test custom bin edges (uniform and non-uniform)
    • Test density normalization
    • Test edge cases (empty data, single value, identical values)
    • Test integration with labels and legends
    • Test all backends (PNG, PDF, ASCII)

Example Requirements

  • Simple, clear example required
    • Demonstrate basic histogram usage
    • Show custom binning options
    • Include multiple datasets with different colors
    • Generate output in all supported formats
    • Add to example/ directory as histogram_demo.f90

Related

This addresses one of the core statistical plot types identified as missing. Histograms are fundamental for:

  • Data exploration and analysis
  • Frequency distribution visualization
  • Statistical modeling and validation
  • Scientific data analysis workflows

Acceptance Criteria

  • Implementation follows SOLID principles
  • Comprehensive test suite with >90% coverage
  • Working example demonstrating key features
  • Documentation updated
  • All backends supported
  • Performance acceptable for datasets up to 10^6 points

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions