diff options
author | CoprDistGit <infra@openeuler.org> | 2023-06-20 05:54:21 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-06-20 05:54:21 +0000 |
commit | 8c095b16ab789935c5fcc70b601f431eff0e97c6 (patch) | |
tree | 23083ed596a77cf9e7684d37abc67af562e97ae2 | |
parent | 4bbbb739552f8fb2da206c965dfbc94824b1cb7a (diff) |
automatic import of python-uniplotopeneuler20.03
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-uniplot.spec | 709 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 711 insertions, 0 deletions
@@ -0,0 +1 @@ +/uniplot-0.10.0.tar.gz diff --git a/python-uniplot.spec b/python-uniplot.spec new file mode 100644 index 0000000..a34565e --- /dev/null +++ b/python-uniplot.spec @@ -0,0 +1,709 @@ +%global _empty_manifest_terminate_build 0 +Name: python-uniplot +Version: 0.10.0 +Release: 1 +Summary: Lightweight plotting to the terminal. 4x resolution via Unicode. +License: MIT +URL: https://pypi.org/project/uniplot/ +Source0: https://mirrors.aliyun.com/pypi/web/packages/84/3c/e12798b1789fbba1185db59c902733e87adfe33a38c43bfc72d9cd826feb/uniplot-0.10.0.tar.gz +BuildArch: noarch + +Requires: python3-numpy + +%description +# Uniplot +[](https://github.com/olavolav/uniplot/actions?query=workflow%3A"Unit+Tests") +[](https://pypi.org/project/uniplot/) +[](https://pepy.tech/project/uniplot) + +Lightweight plotting to the terminal. 4x resolution via Unicode. + + + +When working with production data science code it can be handy to have plotting +tool that does not rely on graphics dependencies or works only in a Jupyter notebook. + +The **use case** that this was built for is to have plots as part of your data science / +machine learning CI pipeline - that way whenever something goes wrong, you get not only +the error and backtrace but also plots that show what the problem was. + + +## Features + +* Unicode drawing, so 4x the resolution (pixels) of usual ASCII plots +* Super simple API +* Interactive mode (pass `interactive=True`) +* Color mode (pass `color=True`) useful in particular when plotting multiple series +* It's fast: Plotting 1M data points takes 100ms thanks to NumPy magic +* Only one dependency: NumPy (but you have that anyway don't you) + +Please note that Unicode drawing will work correctly only when using a font that +fully supports the [Box-drawing character set](https://en.wikipedia.org/wiki/Box-drawing_character). +Please refer to [this page for a (incomplete) list of supported fonts](https://www.fileformat.info/info/unicode/block/block_elements/fontsupport.htm). + + +## Examples + +Note that all the examples are without color and plotting only a single series od data. For using color see the GIF example above. + +### Plot sine wave + +```python +import math +x = [math.sin(i/20)+i/300 for i in range(600)] +from uniplot import plot +plot(x, title="Sine wave") +``` + +Result: +``` + Sine wave +┌────────────────────────────────────────────────────────────┐ +│ ▟▀▚ │ +│ ▗▘ ▝▌ │ +│ ▗▛▜▖ ▞ ▐ │ +│ ▞ ▜ ▗▌ ▌ │ 2 +│ ▟▀▙ ▗▘ ▝▌ ▐ ▜ │ +│ ▐▘ ▝▖ ▞ ▜ ▌ ▝▌ │ +│ ▗▛▜▖ ▛ ▜ ▗▌ ▝▌ ▐▘ ▜ │ +│ ▛ ▙ ▗▘ ▝▖ ▐ ▚ ▞ ▝▌ │ +│ ▟▀▖ ▐▘ ▝▖ ▟ ▚ ▌ ▝▖ ▗▌ ▜▄│ 1 +│ ▐▘ ▐▖ ▛ ▙ ▌ ▐▖ ▗▘ ▚ ▞ │ +│ ▛ ▙ ▗▘ ▐▖ ▐ ▙ ▞ ▝▙▟▘ │ +│▐▘ ▐▖ ▐ ▌ ▛ ▐▖ ▗▘ │ +│▞ ▌ ▌ ▐ ▗▘ ▜▄▛ │ +│▌─────▐────▐▘───────▙──▞────────────────────────────────────│ 0 +│ ▌ ▛ ▝▙▟▘ │ +│ ▜ ▐▘ │ +│ ▙▄▛ │ +└────────────────────────────────────────────────────────────┘ + 100 200 300 400 500 600 +``` + +### Plot global temperature data + +Here we're using Pandas to load and prepare global temperature data from the [Our World in Data GitHub repository](https://github.com/owid/owid-datasets). + +First we load the data, rename a column and and filter the data: + +```python +import pandas as pd +uri = "https://github.com/owid/owid-datasets/raw/master/datasets/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre.csv" +data = pd.read_csv(uri) +data = data.rename(columns={"Global average temperature anomaly (Hadley Centre)": "Global"}) +data = data[data.Entity == "median"] +``` + +Then we can plot it: + +```python +from uniplot import plot +plot(xs=data.Year, ys=data.Global, lines=True, title="Global normalized land-sea temperature anomaly", y_unit=" °C") +``` + +Result: +``` + Global normalized land-sea temperature anomaly +┌────────────────────────────────────────────────────────────┐ +│ ▞▀│ +│ ▐ │ +│ ▐ │ +│ ▗ ▌ │ 0.6 °C +│ ▙ ▗▄ ▛▄▖▗▘▌ ▞ │ +│ ▗▜ ▌ ▜ ▚▞ ▚▞ │ +│ ▐▝▖▐ ▘ │ +│ ▗ ▗ ▌ ▙▌ │ 0.3 °C +│ ▛▖ ▞▙▘ ▘ │ +│ ▖ ▗▄▗▘▐ ▐▘▜ │ +│ ▟ █ ▞ ▜ ▝▄▘ │ +│ ▗▚ ▗ ▖ ▗ ▖▗▞ █▐ ▌ ▘ │ +│▁▁▁▞▐▁▁▗▘▜▗▀▀▌▁▁▁▁▙▁▁▟▁▁▁▙▐▁▁▜▁▌▞▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0 °C +│▚ ▐ ▝▖ ▐ ▛ ▌ ▗▄▐ ▌▗▘▌ ▐▝▌ ▝▘ │ +│ ▌▌ ▌ ▞ ▐▗▘ ▛ ▐▞ ▌ ▐ │ +│ ▝ ▝▖▌ ▐▞ ▝▌ ▚▜▐ │ +│ ▗▌ ▝ ▝ ▌ │ +└────────────────────────────────────────────────────────────┘ +1,950 1,960 1,970 1,980 1,990 2,000 2,010 +``` + + +## Parameters + +The `plot` function accepts a number of parameters, all listed below. Note that only +`ys` is required, all others are optional. + +There is also a `plot_to_string` function with the same signature, if you want the result as a list of strings, to include the output elsewhere. + +### Data + +* `xs` - The x coordinates of the points to plot. Can either be `None`, or a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. Defaults to `None`, meaning that the x axis will be just the sample index of +`ys`. +* `ys` - The y coordinates of the points to plot. Can either be a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. + +In both cases, NaN values are ignored. + +### Options + +In alphabetical order: + +* `color` - Draw series in color. Defaults to `False` when plotting a single series, and to `True` when plotting multiple. +* `force_ascii` - Force ASCII characters for plotting only. This can be useful for compatibility, for example when using uniplot inside of CI/CD systems that do not support Unicode. Defaults to `False`. +* `height` - The height of the plotting region, in characters. Default is `17`. +* `interactive` - Enable interactive mode. Defaults to `False`. +* `legend_labels` - Labels for the series. Can be `None` or a list of strings. Defaults to `None`. +* `lines` - Enable lines between points. Can either be `True` or `False`, or a list of those values for plotting multiple series. Defaults to `False`. +* `line_length_hard_cap` - Enforce a hard limit on the number of characters per line of the plot area. This may override the `width` option if there is not enough space. Defaults to `None`. +* `title` - The title of the plot. Defaults to `None`. +* `width` - The width of the plotting region, in characters. Default is `60`. Note that if the `line_length_hard_cap` option is used and there is not enough space, the actual width may be smaller. +* `x_as_log` - Plot the x axis as logarithmic scale. Defaults to `False`. +* `x_gridlines` - A list of x values that have a vertical line for better orientation. Defaults to `[0]`, or to `[]` if `x_as_log` is enabled. +* `x_max` - Maximum x value of the view. Defaults to a value that shows all data points. +* `x_min` - Minimum x value of the view. Defaults to a value that shows all data points. +* `x_unit` - Unit of the x axis. This is a string that is appended to the axis labels. Defaults to `""`. +* `y_as_log` - Plot the y axis as logarithmic scale. Defaults to `False`. +* `y_gridlines` - A list of y values that have a horizontal line for better orientation. Defaults to `[0]`, or to `[]` if `y_as_log` is enabled. +* `y_max` - Maximum y value of the view. Defaults to a value that shows all data points. +* `y_min` - Minimum y value of the view. Defaults to a value that shows all data points. +* `y_unit` - Unit of the y axis. This is a string that is appended to the axis labels. Defaults to `""`. + + +## Experimental features + +For convenience there is also a `histogram` function that accepts one or more series and +plots bar-chart like histograms. It will automatically discretize the series into a +number of bins given by the `bins` option and display the result. + +When calling the `histogram` function, the `lines` option is `True` by default. + +Example: + +```python +import numpy as np +x = np.sin(np.linspace(1, 1000)) +from uniplot import histogram +histogram(x) +``` + +Result: +``` +┌────────────────────────────────────────────────────────────┐ +│ ▛▀▀▌ │ ▐▀▀▜ │ 5 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▀▀▀▌ │ ▐▀▀▀ ▝▀▀▜ │ 4 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▙▄▄▄▄▄▖ │ ▗▄▄▄ ▐ ▐ │ 3 +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ ▐▀▀▀ ▝▀▀▀ ▐ │ 2 +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐▄▄▟ ▐ │ 1 +│ ▌ │ ▐ │ +│ ▌ │ ▐ │ +│▄▄▄▌▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▄▄▄│ 0 +└────────────────────────────────────────────────────────────┘ + -1 0 1 +``` + + +## Installation + +Install via pip using: + +``` +pip install uniplot +``` + + +## Contributing + +Clone this repository, and install dependecies via `poetry install`. + +You can run the tests vie `poetry run ./run_tests` to make sure your setup is good. Then proceed with issues, PRs etc. the usual way. + + +%package -n python3-uniplot +Summary: Lightweight plotting to the terminal. 4x resolution via Unicode. +Provides: python-uniplot +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-uniplot +# Uniplot +[](https://github.com/olavolav/uniplot/actions?query=workflow%3A"Unit+Tests") +[](https://pypi.org/project/uniplot/) +[](https://pepy.tech/project/uniplot) + +Lightweight plotting to the terminal. 4x resolution via Unicode. + + + +When working with production data science code it can be handy to have plotting +tool that does not rely on graphics dependencies or works only in a Jupyter notebook. + +The **use case** that this was built for is to have plots as part of your data science / +machine learning CI pipeline - that way whenever something goes wrong, you get not only +the error and backtrace but also plots that show what the problem was. + + +## Features + +* Unicode drawing, so 4x the resolution (pixels) of usual ASCII plots +* Super simple API +* Interactive mode (pass `interactive=True`) +* Color mode (pass `color=True`) useful in particular when plotting multiple series +* It's fast: Plotting 1M data points takes 100ms thanks to NumPy magic +* Only one dependency: NumPy (but you have that anyway don't you) + +Please note that Unicode drawing will work correctly only when using a font that +fully supports the [Box-drawing character set](https://en.wikipedia.org/wiki/Box-drawing_character). +Please refer to [this page for a (incomplete) list of supported fonts](https://www.fileformat.info/info/unicode/block/block_elements/fontsupport.htm). + + +## Examples + +Note that all the examples are without color and plotting only a single series od data. For using color see the GIF example above. + +### Plot sine wave + +```python +import math +x = [math.sin(i/20)+i/300 for i in range(600)] +from uniplot import plot +plot(x, title="Sine wave") +``` + +Result: +``` + Sine wave +┌────────────────────────────────────────────────────────────┐ +│ ▟▀▚ │ +│ ▗▘ ▝▌ │ +│ ▗▛▜▖ ▞ ▐ │ +│ ▞ ▜ ▗▌ ▌ │ 2 +│ ▟▀▙ ▗▘ ▝▌ ▐ ▜ │ +│ ▐▘ ▝▖ ▞ ▜ ▌ ▝▌ │ +│ ▗▛▜▖ ▛ ▜ ▗▌ ▝▌ ▐▘ ▜ │ +│ ▛ ▙ ▗▘ ▝▖ ▐ ▚ ▞ ▝▌ │ +│ ▟▀▖ ▐▘ ▝▖ ▟ ▚ ▌ ▝▖ ▗▌ ▜▄│ 1 +│ ▐▘ ▐▖ ▛ ▙ ▌ ▐▖ ▗▘ ▚ ▞ │ +│ ▛ ▙ ▗▘ ▐▖ ▐ ▙ ▞ ▝▙▟▘ │ +│▐▘ ▐▖ ▐ ▌ ▛ ▐▖ ▗▘ │ +│▞ ▌ ▌ ▐ ▗▘ ▜▄▛ │ +│▌─────▐────▐▘───────▙──▞────────────────────────────────────│ 0 +│ ▌ ▛ ▝▙▟▘ │ +│ ▜ ▐▘ │ +│ ▙▄▛ │ +└────────────────────────────────────────────────────────────┘ + 100 200 300 400 500 600 +``` + +### Plot global temperature data + +Here we're using Pandas to load and prepare global temperature data from the [Our World in Data GitHub repository](https://github.com/owid/owid-datasets). + +First we load the data, rename a column and and filter the data: + +```python +import pandas as pd +uri = "https://github.com/owid/owid-datasets/raw/master/datasets/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre.csv" +data = pd.read_csv(uri) +data = data.rename(columns={"Global average temperature anomaly (Hadley Centre)": "Global"}) +data = data[data.Entity == "median"] +``` + +Then we can plot it: + +```python +from uniplot import plot +plot(xs=data.Year, ys=data.Global, lines=True, title="Global normalized land-sea temperature anomaly", y_unit=" °C") +``` + +Result: +``` + Global normalized land-sea temperature anomaly +┌────────────────────────────────────────────────────────────┐ +│ ▞▀│ +│ ▐ │ +│ ▐ │ +│ ▗ ▌ │ 0.6 °C +│ ▙ ▗▄ ▛▄▖▗▘▌ ▞ │ +│ ▗▜ ▌ ▜ ▚▞ ▚▞ │ +│ ▐▝▖▐ ▘ │ +│ ▗ ▗ ▌ ▙▌ │ 0.3 °C +│ ▛▖ ▞▙▘ ▘ │ +│ ▖ ▗▄▗▘▐ ▐▘▜ │ +│ ▟ █ ▞ ▜ ▝▄▘ │ +│ ▗▚ ▗ ▖ ▗ ▖▗▞ █▐ ▌ ▘ │ +│▁▁▁▞▐▁▁▗▘▜▗▀▀▌▁▁▁▁▙▁▁▟▁▁▁▙▐▁▁▜▁▌▞▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0 °C +│▚ ▐ ▝▖ ▐ ▛ ▌ ▗▄▐ ▌▗▘▌ ▐▝▌ ▝▘ │ +│ ▌▌ ▌ ▞ ▐▗▘ ▛ ▐▞ ▌ ▐ │ +│ ▝ ▝▖▌ ▐▞ ▝▌ ▚▜▐ │ +│ ▗▌ ▝ ▝ ▌ │ +└────────────────────────────────────────────────────────────┘ +1,950 1,960 1,970 1,980 1,990 2,000 2,010 +``` + + +## Parameters + +The `plot` function accepts a number of parameters, all listed below. Note that only +`ys` is required, all others are optional. + +There is also a `plot_to_string` function with the same signature, if you want the result as a list of strings, to include the output elsewhere. + +### Data + +* `xs` - The x coordinates of the points to plot. Can either be `None`, or a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. Defaults to `None`, meaning that the x axis will be just the sample index of +`ys`. +* `ys` - The y coordinates of the points to plot. Can either be a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. + +In both cases, NaN values are ignored. + +### Options + +In alphabetical order: + +* `color` - Draw series in color. Defaults to `False` when plotting a single series, and to `True` when plotting multiple. +* `force_ascii` - Force ASCII characters for plotting only. This can be useful for compatibility, for example when using uniplot inside of CI/CD systems that do not support Unicode. Defaults to `False`. +* `height` - The height of the plotting region, in characters. Default is `17`. +* `interactive` - Enable interactive mode. Defaults to `False`. +* `legend_labels` - Labels for the series. Can be `None` or a list of strings. Defaults to `None`. +* `lines` - Enable lines between points. Can either be `True` or `False`, or a list of those values for plotting multiple series. Defaults to `False`. +* `line_length_hard_cap` - Enforce a hard limit on the number of characters per line of the plot area. This may override the `width` option if there is not enough space. Defaults to `None`. +* `title` - The title of the plot. Defaults to `None`. +* `width` - The width of the plotting region, in characters. Default is `60`. Note that if the `line_length_hard_cap` option is used and there is not enough space, the actual width may be smaller. +* `x_as_log` - Plot the x axis as logarithmic scale. Defaults to `False`. +* `x_gridlines` - A list of x values that have a vertical line for better orientation. Defaults to `[0]`, or to `[]` if `x_as_log` is enabled. +* `x_max` - Maximum x value of the view. Defaults to a value that shows all data points. +* `x_min` - Minimum x value of the view. Defaults to a value that shows all data points. +* `x_unit` - Unit of the x axis. This is a string that is appended to the axis labels. Defaults to `""`. +* `y_as_log` - Plot the y axis as logarithmic scale. Defaults to `False`. +* `y_gridlines` - A list of y values that have a horizontal line for better orientation. Defaults to `[0]`, or to `[]` if `y_as_log` is enabled. +* `y_max` - Maximum y value of the view. Defaults to a value that shows all data points. +* `y_min` - Minimum y value of the view. Defaults to a value that shows all data points. +* `y_unit` - Unit of the y axis. This is a string that is appended to the axis labels. Defaults to `""`. + + +## Experimental features + +For convenience there is also a `histogram` function that accepts one or more series and +plots bar-chart like histograms. It will automatically discretize the series into a +number of bins given by the `bins` option and display the result. + +When calling the `histogram` function, the `lines` option is `True` by default. + +Example: + +```python +import numpy as np +x = np.sin(np.linspace(1, 1000)) +from uniplot import histogram +histogram(x) +``` + +Result: +``` +┌────────────────────────────────────────────────────────────┐ +│ ▛▀▀▌ │ ▐▀▀▜ │ 5 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▀▀▀▌ │ ▐▀▀▀ ▝▀▀▜ │ 4 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▙▄▄▄▄▄▖ │ ▗▄▄▄ ▐ ▐ │ 3 +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ ▐▀▀▀ ▝▀▀▀ ▐ │ 2 +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐▄▄▟ ▐ │ 1 +│ ▌ │ ▐ │ +│ ▌ │ ▐ │ +│▄▄▄▌▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▄▄▄│ 0 +└────────────────────────────────────────────────────────────┘ + -1 0 1 +``` + + +## Installation + +Install via pip using: + +``` +pip install uniplot +``` + + +## Contributing + +Clone this repository, and install dependecies via `poetry install`. + +You can run the tests vie `poetry run ./run_tests` to make sure your setup is good. Then proceed with issues, PRs etc. the usual way. + + +%package help +Summary: Development documents and examples for uniplot +Provides: python3-uniplot-doc +%description help +# Uniplot +[](https://github.com/olavolav/uniplot/actions?query=workflow%3A"Unit+Tests") +[](https://pypi.org/project/uniplot/) +[](https://pepy.tech/project/uniplot) + +Lightweight plotting to the terminal. 4x resolution via Unicode. + + + +When working with production data science code it can be handy to have plotting +tool that does not rely on graphics dependencies or works only in a Jupyter notebook. + +The **use case** that this was built for is to have plots as part of your data science / +machine learning CI pipeline - that way whenever something goes wrong, you get not only +the error and backtrace but also plots that show what the problem was. + + +## Features + +* Unicode drawing, so 4x the resolution (pixels) of usual ASCII plots +* Super simple API +* Interactive mode (pass `interactive=True`) +* Color mode (pass `color=True`) useful in particular when plotting multiple series +* It's fast: Plotting 1M data points takes 100ms thanks to NumPy magic +* Only one dependency: NumPy (but you have that anyway don't you) + +Please note that Unicode drawing will work correctly only when using a font that +fully supports the [Box-drawing character set](https://en.wikipedia.org/wiki/Box-drawing_character). +Please refer to [this page for a (incomplete) list of supported fonts](https://www.fileformat.info/info/unicode/block/block_elements/fontsupport.htm). + + +## Examples + +Note that all the examples are without color and plotting only a single series od data. For using color see the GIF example above. + +### Plot sine wave + +```python +import math +x = [math.sin(i/20)+i/300 for i in range(600)] +from uniplot import plot +plot(x, title="Sine wave") +``` + +Result: +``` + Sine wave +┌────────────────────────────────────────────────────────────┐ +│ ▟▀▚ │ +│ ▗▘ ▝▌ │ +│ ▗▛▜▖ ▞ ▐ │ +│ ▞ ▜ ▗▌ ▌ │ 2 +│ ▟▀▙ ▗▘ ▝▌ ▐ ▜ │ +│ ▐▘ ▝▖ ▞ ▜ ▌ ▝▌ │ +│ ▗▛▜▖ ▛ ▜ ▗▌ ▝▌ ▐▘ ▜ │ +│ ▛ ▙ ▗▘ ▝▖ ▐ ▚ ▞ ▝▌ │ +│ ▟▀▖ ▐▘ ▝▖ ▟ ▚ ▌ ▝▖ ▗▌ ▜▄│ 1 +│ ▐▘ ▐▖ ▛ ▙ ▌ ▐▖ ▗▘ ▚ ▞ │ +│ ▛ ▙ ▗▘ ▐▖ ▐ ▙ ▞ ▝▙▟▘ │ +│▐▘ ▐▖ ▐ ▌ ▛ ▐▖ ▗▘ │ +│▞ ▌ ▌ ▐ ▗▘ ▜▄▛ │ +│▌─────▐────▐▘───────▙──▞────────────────────────────────────│ 0 +│ ▌ ▛ ▝▙▟▘ │ +│ ▜ ▐▘ │ +│ ▙▄▛ │ +└────────────────────────────────────────────────────────────┘ + 100 200 300 400 500 600 +``` + +### Plot global temperature data + +Here we're using Pandas to load and prepare global temperature data from the [Our World in Data GitHub repository](https://github.com/owid/owid-datasets). + +First we load the data, rename a column and and filter the data: + +```python +import pandas as pd +uri = "https://github.com/owid/owid-datasets/raw/master/datasets/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre/Global%20average%20temperature%20anomaly%20-%20Hadley%20Centre.csv" +data = pd.read_csv(uri) +data = data.rename(columns={"Global average temperature anomaly (Hadley Centre)": "Global"}) +data = data[data.Entity == "median"] +``` + +Then we can plot it: + +```python +from uniplot import plot +plot(xs=data.Year, ys=data.Global, lines=True, title="Global normalized land-sea temperature anomaly", y_unit=" °C") +``` + +Result: +``` + Global normalized land-sea temperature anomaly +┌────────────────────────────────────────────────────────────┐ +│ ▞▀│ +│ ▐ │ +│ ▐ │ +│ ▗ ▌ │ 0.6 °C +│ ▙ ▗▄ ▛▄▖▗▘▌ ▞ │ +│ ▗▜ ▌ ▜ ▚▞ ▚▞ │ +│ ▐▝▖▐ ▘ │ +│ ▗ ▗ ▌ ▙▌ │ 0.3 °C +│ ▛▖ ▞▙▘ ▘ │ +│ ▖ ▗▄▗▘▐ ▐▘▜ │ +│ ▟ █ ▞ ▜ ▝▄▘ │ +│ ▗▚ ▗ ▖ ▗ ▖▗▞ █▐ ▌ ▘ │ +│▁▁▁▞▐▁▁▗▘▜▗▀▀▌▁▁▁▁▙▁▁▟▁▁▁▙▐▁▁▜▁▌▞▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│ 0 °C +│▚ ▐ ▝▖ ▐ ▛ ▌ ▗▄▐ ▌▗▘▌ ▐▝▌ ▝▘ │ +│ ▌▌ ▌ ▞ ▐▗▘ ▛ ▐▞ ▌ ▐ │ +│ ▝ ▝▖▌ ▐▞ ▝▌ ▚▜▐ │ +│ ▗▌ ▝ ▝ ▌ │ +└────────────────────────────────────────────────────────────┘ +1,950 1,960 1,970 1,980 1,990 2,000 2,010 +``` + + +## Parameters + +The `plot` function accepts a number of parameters, all listed below. Note that only +`ys` is required, all others are optional. + +There is also a `plot_to_string` function with the same signature, if you want the result as a list of strings, to include the output elsewhere. + +### Data + +* `xs` - The x coordinates of the points to plot. Can either be `None`, or a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. Defaults to `None`, meaning that the x axis will be just the sample index of +`ys`. +* `ys` - The y coordinates of the points to plot. Can either be a list or NumPy array for plotting a single series, or a list of those for plotting multiple series. + +In both cases, NaN values are ignored. + +### Options + +In alphabetical order: + +* `color` - Draw series in color. Defaults to `False` when plotting a single series, and to `True` when plotting multiple. +* `force_ascii` - Force ASCII characters for plotting only. This can be useful for compatibility, for example when using uniplot inside of CI/CD systems that do not support Unicode. Defaults to `False`. +* `height` - The height of the plotting region, in characters. Default is `17`. +* `interactive` - Enable interactive mode. Defaults to `False`. +* `legend_labels` - Labels for the series. Can be `None` or a list of strings. Defaults to `None`. +* `lines` - Enable lines between points. Can either be `True` or `False`, or a list of those values for plotting multiple series. Defaults to `False`. +* `line_length_hard_cap` - Enforce a hard limit on the number of characters per line of the plot area. This may override the `width` option if there is not enough space. Defaults to `None`. +* `title` - The title of the plot. Defaults to `None`. +* `width` - The width of the plotting region, in characters. Default is `60`. Note that if the `line_length_hard_cap` option is used and there is not enough space, the actual width may be smaller. +* `x_as_log` - Plot the x axis as logarithmic scale. Defaults to `False`. +* `x_gridlines` - A list of x values that have a vertical line for better orientation. Defaults to `[0]`, or to `[]` if `x_as_log` is enabled. +* `x_max` - Maximum x value of the view. Defaults to a value that shows all data points. +* `x_min` - Minimum x value of the view. Defaults to a value that shows all data points. +* `x_unit` - Unit of the x axis. This is a string that is appended to the axis labels. Defaults to `""`. +* `y_as_log` - Plot the y axis as logarithmic scale. Defaults to `False`. +* `y_gridlines` - A list of y values that have a horizontal line for better orientation. Defaults to `[0]`, or to `[]` if `y_as_log` is enabled. +* `y_max` - Maximum y value of the view. Defaults to a value that shows all data points. +* `y_min` - Minimum y value of the view. Defaults to a value that shows all data points. +* `y_unit` - Unit of the y axis. This is a string that is appended to the axis labels. Defaults to `""`. + + +## Experimental features + +For convenience there is also a `histogram` function that accepts one or more series and +plots bar-chart like histograms. It will automatically discretize the series into a +number of bins given by the `bins` option and display the result. + +When calling the `histogram` function, the `lines` option is `True` by default. + +Example: + +```python +import numpy as np +x = np.sin(np.linspace(1, 1000)) +from uniplot import histogram +histogram(x) +``` + +Result: +``` +┌────────────────────────────────────────────────────────────┐ +│ ▛▀▀▌ │ ▐▀▀▜ │ 5 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▀▀▀▌ │ ▐▀▀▀ ▝▀▀▜ │ 4 +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ │ +│ ▌ ▙▄▄▄▄▄▖ │ ▗▄▄▄ ▐ ▐ │ 3 +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▌ │ ▐ ▐ ▐ ▐ │ +│ ▌ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ ▐▀▀▀ ▝▀▀▀ ▐ │ 2 +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐ ▐ ▐ │ +│ ▌ │ ▐▄▄▟ ▐ │ 1 +│ ▌ │ ▐ │ +│ ▌ │ ▐ │ +│▄▄▄▌▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁│▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▄▄▄│ 0 +└────────────────────────────────────────────────────────────┘ + -1 0 1 +``` + + +## Installation + +Install via pip using: + +``` +pip install uniplot +``` + + +## Contributing + +Clone this repository, and install dependecies via `poetry install`. + +You can run the tests vie `poetry run ./run_tests` to make sure your setup is good. Then proceed with issues, PRs etc. the usual way. + + +%prep +%autosetup -n uniplot-0.10.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-uniplot -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.10.0-1 +- Package Spec generated @@ -0,0 +1 @@ +3cee09eea0112cef098f557e96760e9e uniplot-0.10.0.tar.gz |