Skip to content

Commit

Permalink
Merge pull request #84 from phobson/update-readme
Browse files Browse the repository at this point in the history
update example figure for readme
  • Loading branch information
phobson authored Nov 3, 2023
2 parents 60e0c3c + 41c0131 commit 95de4ae
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 101 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[run]
source = probscale
branch = True
include = probscale/*.py
omit =
probscale/tests/*

Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: black
name: Lint with Black

on: [pull_request]
on: [push, pull_request]

jobs:
black:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Black Code Formatter
uses: lgeiger/[email protected]
with:
args: ". --check --exclude=docs/*"
- uses: actions/checkout@v3
- uses: psf/black@stable
6 changes: 3 additions & 3 deletions .github/workflows/check-test-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage via codecov
name: Coverage (with doctests)
on:
push:
branches: [ master ]
Expand All @@ -19,9 +19,9 @@ jobs:
python -m pip install --upgrade pip
pip install pytest pytest-cov pytest-mpl coverage docopt
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install scipy
pip install scipy seaborn
export MPL_IMGCOMP_TOLERANCE=20
coverage run --source probscale check_probscale.py --doctest-modules --mpl --cov-report=xml
coverage run -m pytest --mpl --doctest-glob="probscale/*.py" --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-runtests-all.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Image comparison tests
name: Run units test (w/ img comps)

on:
push:
Expand All @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -31,4 +31,4 @@ jobs:
- name: Test with pytest
run: |
export MPL_IMGCOMP_TOLERANCE=20
python check_probscale.py --mpl --doctest-modules
python -m pytest --mpl
31 changes: 1 addition & 30 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Ready to contribute? Here's how to set up `probscale` for local development.

5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::

$ python check_probscale.py --mpl --pep8 --cov
$ python -m pytest --mpl --pep8 --cov

6. Commit your changes and push your branch to GitHub::

Expand Down Expand Up @@ -115,35 +115,6 @@ To run a subset of tests::
$ py.test tests.test_probscale


Configuring Sublime Text 3 to run the tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In Sublime, got to Tools -> Build System -> New Build System.
Then add the following configuration and save as "probscale.sublime-build"::

{
"working_dir": "<path to the git repository>",
"cmd": "<full path of the python executable> check_probscale.py --verbose <other pytest options>",
}


Configuring Atom to run the tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In Atom, install the build_ package, create a new file called ".atom-build.yml" in the
top level of the project directory, and add the following contents::

cmd: "<full path of the python executable>"
name: "probscale"
args:
- check_probscale.py
- --verbose
- <other pytest options ...>
cwd: <path to the git repository>
sh: false
keymap: ctrl-b
atomCommandName: namespace:testprobscale

After this, hitting ctrl+b in either text editor will run the test suite.

.. _build: https://atom.io/packages/build
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

Real probability scales for matplotlib

![Code Style](https://github.com/matplotlib/mpl-probscale/workflows/black/badge.svg)
![Coverage](https://github.com/matplotlib/mpl-probscale/workflows/Coverage%20via%20codecov/badge.svg)
![Linter](https://github.com/matplotlib/mpl-probscale/workflows/Lint%20with%20flake8/badge.svg)
![Basic Tests](https://github.com/matplotlib/mpl-probscale/workflows/Basic%20unit%20tests/badge.svg)
![Image Comparisons](https://github.com/matplotlib/mpl-probscale/workflows/Image%20comparison%20tests/badge.svg)
![Tests](https://github.com/matplotlib/mpl-probscale/workflows/Image%20comparison%20tests/badge.svg)

[Sphinx Docs](http://matplotlib.org/mpl-probscale/)

Expand All @@ -30,38 +28,20 @@ cd mpl-probscale
pip install -e .
```

### Additional Depedencies

This library depends on **pytest** framework.
The current release version does not have it listed as a hard dependency, however.
So for now you will need to install ``pytest`` yourself to use mpl-probscale:

`pip install pytest`

or

`conda install pytest --channel=conda-forge`

In the next release, this depedency will be made optional.

## Quick start

Simply importing `probscale` lets you use probability scales in your matplotlib figures:

```python
import matplotlib.pyplot as plt
import probscale
import seaborn
clear_bkgd = {'axes.facecolor':'none', 'figure.facecolor':'none'}
seaborn.set(style='ticks', context='notebook', rc=clear_bkgd)

fig, ax = plt.subplots(figsize=(8, 4))
ax.set_ylim(1e-2, 1e2)
ax.set_yscale('log')

ax.set_xlim(0.5, 99.5)
ax.set_xscale('prob')
seaborn.despine(fig=fig)
```

![Alt text](docs/img/example.png "Example axes")
Expand Down
7 changes: 0 additions & 7 deletions check_probscale.py

This file was deleted.

38 changes: 38 additions & 0 deletions docs/examples/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# %%
from pathlib import Path

from matplotlib import pyplot
from scipy import stats
import probscale # nothing else needed

beta = stats.beta(a=3, b=4)
weibull = stats.weibull_min(c=5)
scales = [
{"scale": {"value": "linear"}, "label": "Linear (built-in)"},
{"scale": {"value": "log", "base": 10}, "label": "Log. Base 10 (built-in)"},
{"scale": {"value": "log", "base": 2}, "label": "Log. Base 2 (built-in)"},
{"scale": {"value": "logit"}, "label": "Logit (built-in)"},
{"scale": {"value": "prob"}, "label": "Standard Normal Probability (this package)"},
{
"scale": {"value": "prob", "dist": weibull},
"label": "Weibull probability scale, c=5 (this package)",
},
{
"scale": {"value": "prob", "dist": beta},
"label": "Beta probability scale, α=3 & β=4 (this package)",
},
]

N = len(scales)
fig, axes = pyplot.subplots(nrows=N, figsize=(9, N - 1), constrained_layout=True)
for scale, ax in zip(scales, axes.flat):
ax.set_xscale(**scale["scale"])
ax.text(0.0, 0.1, scale["label"] + " →", transform=ax.transAxes)
ax.set_xlim(left=0.5, right=99.5)
ax.set_yticks([])
ax.spines.left.set_visible(False)
ax.spines.right.set_visible(False)
ax.spines.top.set_visible(False)

outpath = Path(__file__).parent.joinpath("../img/example.png").resolve()
fig.savefig(outpath, dpi=300)
Binary file modified docs/img/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions docs/sphinxext/ipython_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout):
i = 0
decorator = None
while 1:

if i == N:
# nothing left to parse -- the last line
break
Expand Down Expand Up @@ -215,7 +214,6 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout):

rest = []
while i < N:

# look ahead; if the next line is blank, or a comment, or
# an output line, we're done

Expand Down Expand Up @@ -278,7 +276,6 @@ class EmbeddedSphinxShell(object):
"""An embedded IPython instance to run inside Sphinx"""

def __init__(self, exec_lines=None, state=None):

self.cout = DecodingStringIO("")

if exec_lines is None:
Expand Down Expand Up @@ -526,7 +523,6 @@ def process_output(
TAB = " " * 4

if is_doctest and output is not None:

found = output
found = found.strip()
submitted = data.strip()
Expand Down Expand Up @@ -693,7 +689,6 @@ def process_pure_python(self, content):
ct = 0

for lineno, line in enumerate(content):

line_stripped = line.strip()
if not len(line):
output.append(line)
Expand Down Expand Up @@ -770,7 +765,6 @@ def custom_doctest(self, decorator, input_lines, found, submitted):


class IPythonDirective(Directive):

has_content = True
required_arguments = 0
optional_arguments = 4 # python, suppress, verbatim, doctest
Expand Down Expand Up @@ -973,7 +967,6 @@ def setup(app):

# Simple smoke test, needs to be converted to a proper automatic test.
def test():

examples = [
r"""
In [9]: pwd
Expand Down
2 changes: 0 additions & 2 deletions docs/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
def format_template(template, **kw):
return jinja2.Template(template).render(**kw)


except ImportError:
import jinja

Expand Down Expand Up @@ -652,7 +651,6 @@ def render_figures(
close_figs = not context or close_figs

for i, code_piece in enumerate(code_pieces):

if not context or config.plot_apply_rcparams:
clear_state(config.plot_rcparams, close_figs)
elif close_figs:
Expand Down
6 changes: 1 addition & 5 deletions docs/sphinxext/plot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ def __init__(self, filename, target_dir):
if not op.exists(outfilename) or (
op.getmtime(outfilename) < op.getmtime(filename)
):

self.exec_file()
else:

print("skipping {0}".format(self.filename))

@property
Expand Down Expand Up @@ -226,8 +224,7 @@ def plotfunc(self):
return ""

def extract_docstring(self):
""" Extract a module-level docstring
"""
"""Extract a module-level docstring"""
lines = open(self.filename).readlines()
start_row = 0
if lines[0].startswith("#!"):
Expand Down Expand Up @@ -332,7 +329,6 @@ def main(app):

# Write individual example files
for filename in glob.glob(op.join(source_dir, "*.py")):

ex = ExampleGenerator(filename, target_dir)

banner_data.append(
Expand Down
14 changes: 0 additions & 14 deletions probscale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
from pkg_resources import resource_filename

import probscale


def test(*args):
try:
import pytest
except ImportError:
raise ImportError("`pytest` is required to run the test suite")

options = [resource_filename("probscale", "tests")]
options.extend(list(args))
return pytest.main(options)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def search(substr: str, content: str):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
INSTALL_REQUIRES = ["numpy", "matplotlib"]
PACKAGE_DATA = {
Expand Down

0 comments on commit 95de4ae

Please sign in to comment.