Skip to content

Commit

Permalink
Merge pull request #33 from alan-turing-institute/32-color-swatch-fon…
Browse files Browse the repository at this point in the history
…t-size

32 color swatch font size
  • Loading branch information
jack89roberts authored Jan 2, 2024
2 parents 0ed9c7c + 4051046 commit 9d1a0a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
27 changes: 13 additions & 14 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
run: |
Expand All @@ -39,21 +39,20 @@ jobs:
os: [ubuntu-latest, windows-latest, macOS-latest]
arch: [auto]
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
#- 'pypy-3.7' # see https://github.com/pandas-dev/pandas/issues/44253
- '3.11'
- '3.12'
depsize:
- 'minimal'
- 'full'

steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -87,11 +86,11 @@ jobs:
mv .coverage "../.coverage.${CUSTOM_RUNNER_ID}"
cd ..
- name: Set up Python 3.8 to combine coverage Linux
- name: Set up Python to combine coverage Linux
if: runner.os == 'Linux'
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.11

- name: Combine coverage Linux
if: runner.os == 'Linux'
Expand All @@ -103,7 +102,7 @@ jobs:
find . -name coverage.xml
- name: Codecov Upload
uses: codecov/codecov-action@v2.1.0
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/coverage.xml
files: ./tests/coverage.xml
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion distinctipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

name = "distinctipy"

__version__ = "1.2.3"
__version__ = "1.3.0"

# Expose these module names and their internals in the top-level API
__external__ = ["distinctipy"]
Expand Down
9 changes: 8 additions & 1 deletion distinctipy/distinctipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def color_swatch(
ax=None,
title=None,
one_row=None,
fontsize=None,
):
"""
Display the colours defined in a list of colors.
Expand All @@ -360,6 +361,9 @@ def color_swatch(
:param one_row: If True display colours on one row, if False as a grid. If
one_row=None a grid is used when there are more than 8 colours.
:param fontsize: Fontsize of text on colour swatch. If None fontsize will attempt to
be set to an appropriate size based on the number of colours.
:return:
"""
import matplotlib.colors
Expand All @@ -377,6 +381,9 @@ def color_swatch(
else:
n_grid = math.ceil(np.sqrt(len(colors)))

if fontsize is None:
fontsize = 60 / n_grid

width = 1
height = 1

Expand Down Expand Up @@ -413,7 +420,7 @@ def color_swatch(
x + (width / 2),
y + (height / 2),
matplotlib.colors.rgb2hex(color),
fontsize=60 / np.sqrt(len(colors)),
fontsize=fontsize,
ha="center",
color=get_text_color(color, threshold=text_threshold),
)
Expand Down

0 comments on commit 9d1a0a2

Please sign in to comment.