|
| 1 | +# nc-time-axis |
| 2 | + |
| 3 | +<h4 align="center"> |
| 4 | + Support for a cftime axis in matplotlib |
| 5 | +</h4> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | +<a href="https://anaconda.org/conda-forge/nc-time-axis"> |
| 9 | +<img src="https://img.shields.io/conda/vn/conda-forge/nc-time-axis?color=orange&label=conda-forge&logo=conda-forge&logoColor=white" |
| 10 | + alt="conda-forge"></a> |
| 11 | +<a href="https://pypi.org/project/nc-time-axis/"> |
| 12 | +<img src="https://img.shields.io/pypi/v/nc-time-axis?color=orange&label=pypi&logo=python&logoColor=white" |
| 13 | + alt="pypi"></a> |
| 14 | +<a href="https://github.com/psf/black"> |
| 15 | +<img src="https://img.shields.io/badge/code%20style-black-000000.svg" |
| 16 | + alt="black"></a> |
| 17 | +<a href="https://github.com/SciTools/nc-time-axis/blob/master/LICENSE"> |
| 18 | +<img src="https://img.shields.io/github/license/SciTools/nc-time-axis?style=plastic" |
| 19 | + alt="license"></a> |
| 20 | +<a href="https://github.com/SciTools/nc-time-axis/graphs/contributors"> |
| 21 | +<img src="https://img.shields.io/github/contributors/SciTools/nc-time-axis?style=plastic" |
| 22 | + alt="contributors"></a> |
| 23 | +</p> |
| 24 | + |
| 25 | + |
| 26 | +## Installation |
| 27 | +Install `nc-time-axis` either with `conda`: |
| 28 | +```shell |
| 29 | + conda install -c conda-forge nc-time-axis |
| 30 | +``` |
| 31 | +Or `pip`: |
| 32 | +```shell |
| 33 | + pip install nc-time-axis |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +## Example |
| 38 | + |
| 39 | + import random |
| 40 | + |
| 41 | + import cftime |
| 42 | + import matplotlib.pyplot as plt |
| 43 | + |
| 44 | + from nc_time_axis import CalendarDateTime |
| 45 | + |
| 46 | + calendar = "360_day" |
| 47 | + dt = [ |
| 48 | + cftime.datetime(year=2017, month=2, day=day, calendar=calendar) |
| 49 | + for day in range(1, 31) |
| 50 | + ] |
| 51 | + cdt = [CalendarDateTime(item, calendar) for item in dt] |
| 52 | + temperatures = [round(random.uniform(0, 12), 3) for _ in range(len(cdt))] |
| 53 | + |
| 54 | + plt.plot(cdt, temperatures) |
| 55 | + plt.margins(0.1) |
| 56 | + plt.ylim(0, 12) |
| 57 | + plt.xlabel("Date") |
| 58 | + plt.ylabel("Temperature") |
| 59 | + plt.show() |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +## Reference |
| 65 | +* [cftime](https://github.com/Unidata/cftime) - Time-handling functionality from netcdf4-python. |
| 66 | +* [matplotlib](http://matplotlib.org/) - Plotting with Python. |
0 commit comments