Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobwilliams/pyplot-fortran
For generating plots from Fortran using Python's matplotlib.pyplot 📈
https://github.com/jacobwilliams/pyplot-fortran
contour-plot fortran fortran-package-manager matplotlib plot plotting plotting-in-fortran pyplot
Last synced: about 6 hours ago
JSON representation
For generating plots from Fortran using Python's matplotlib.pyplot 📈
- Host: GitHub
- URL: https://github.com/jacobwilliams/pyplot-fortran
- Owner: jacobwilliams
- License: other
- Created: 2015-04-18T16:23:29.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-17T14:04:58.000Z (3 months ago)
- Last Synced: 2024-08-18T15:07:06.894Z (3 months ago)
- Topics: contour-plot, fortran, fortran-package-manager, matplotlib, plot, plotting, plotting-in-fortran, pyplot
- Language: Fortran
- Homepage:
- Size: 2.17 MB
- Stars: 191
- Watchers: 20
- Forks: 52
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Pyplot-Fortran](media/logo.png)
============A simple module for generating plots from Fortran using Python's matplotlib.pyplot.
### Status
[![GitHub release](https://img.shields.io/github/release/jacobwilliams/pyplot-fortran.svg?style=plastic)](https://github.com/jacobwilliams/pyplot-fortran/releases/latest)
![Build Status](https://github.com/jacobwilliams/pyplot-fortran/actions/workflows/CI.yml/badge.svg)
[![codecov](https://codecov.io/gh/jacobwilliams/pyplot-fortran/branch/master/graph/badge.svg?token=BHtd51oUTE)](https://codecov.io/gh/jacobwilliams/pyplot-fortran)### Overview
Currently, this module can be used to generate simple plots from Fortran. Eventually, it may be expanded to provide additional features and other types of plots.
The way it works is simply to generate a Python script with the plotting code, which
is then executed from the command line using the Fortran ```execute_command_line``` function.### Compiling
The module requires a modern Fortran compiler (it uses various Fortran 2003/2008 features such as deferred-length strings). It should work fine with the latest gfortran or ifort compilers.
A `fpm.toml` file is provided for compiling pyplot-fortran with the [Fortran Package Manager](https://github.com/fortran-lang/fpm). For example, to build:
```
fpm build --profile release
```By default, the library is built with double precision (`real64`) real values. Explicitly specifying the real kind can be done using the following processor flags:
Preprocessor flag | Kind | Number of bytes
----------------- | ----- | ---------------
`REAL32` | `real(kind=real32)` | 4
`REAL64` | `real(kind=real64)` | 8
`REAL128` | `real(kind=real128)` | 16For example, to build a single precision version of the library, use:
```
fpm build --profile release --flag "-DREAL32"
```To run the unit tests:
```
fpm test
```To use `pyplot-fortran` within your fpm project, add the following to your `fpm.toml` file:
```toml
[dependencies]
pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git" }
```or, to use a specific version:
```toml
[dependencies]
pyplot-fortran = { git="https://github.com/jacobwilliams/pyplot-fortran.git", tag = "3.3.0" }
```To generate the documentation using [ford](https://github.com/Fortran-FOSS-Programmers/ford), run: ```ford ford.md```
### Supported plot types
* `matplotlib.pyplot.plot` -- 2D/3D plot of lines and/or markers
* `matplotlib.pyplot.bar` -- bar plot
* `matplotlib.pyplot.contour` -- contour plot
* `matplotlib.pyplot.contourf` -- filled contour plot
* `matplotlib.pyplot.imshow` -- image plot
* `matplotlib.pyplot.hist` -- histogram plot
* `matplotlib.pyplot.errorbar` -- errorbar plot
* `mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface` -- surface plot
* `mpl_toolkits.mplot3d.axes3d.Axes3D.plot_wireframe` -- 3D wireframe### Example
The following example generates a plot of the sine function:
```fortran
program testuse,intrinsic :: iso_fortran_env, only: wp => real64
use pyplot_moduleimplicit none
real(wp),dimension(100) :: x,sx
type(pyplot) :: plt
integer :: i!generate some data:
x = [(real(i,wp), i=0,size(x)-1)]/5.0_wp
sx = sin(x)!plot it:
call plt%initialize(grid=.true.,xlabel='angle (rad)',&
title='Plot of $\sin(x)$',legend=.true.)
call plt%add_plot(x,sx,label='$\sin(x)$',linestyle='b-o',markersize=5,linewidth=2)
call plt%savefig('sinx.png', pyfile='sinx.py')end program test
```### Documentation
* The API documentation for the current ```master``` branch can be found [here](https://jacobwilliams.github.io/pyplot-fortran/). This is generated by processing the source files with [FORD](https://github.com/Fortran-FOSS-Programmers/ford).
### See also
* [Matplotlib](https://matplotlib.org)