Skip to main content

Helpers to check if a figure is black and white and colourblind-friendly

Project description

Diagfig

A reviewer asked you for a b/w & colorblind friendly figure? diagfig can be used for a very simple visual checking.

Motivation and disclaimer

The original idea for diagfig was a demo package for getting used to packaging in python and that would have a few helpers to make sure a figure is ready for scientific publication. Additional functionalities may be added in the future, but the current version support colorblindness simulation and low dpi simulation.

This is by no mean my field of research, see references and docstrings for further information.

Other solutions exist for checking in a palette or an image is colorblind friendly, but I needed a tool that I could more easily plug on matplotlib that would check in one line a figure. The code is vastly inspired by other solutions but avoid too many dependencies.

Install the package

pip install diagfig

Examples of use

There are a few options for using diagfig. They are meant to help you to diagnose if a figure require color / quality adjustment before publication. It can be used to simulate colorblindness on your figure as well as black and white. You can also play with the dpi to combine effect of colorbliness and poor export quality. The main options are:

  • diagfig.diagnose_figure: a function taking a figure as argument and returning a diagnosed figure.
  • diagfig.diag_it: a decorator automatically generating a diagnosed figure.
  • diagfig.FigureDiag: a subclass of matpotlib.figure.Figure with an additional diag method returning a "diagnosed" figure.

Use of the main function diagnose_figure:

import numpy as np
import matplotlib.pyplot as plt
import diagfig

# creating a dummy figure in matplotlib
fig, ax = plt.subplots()
x = np.arange(10)
y_low = x * .5
y_high = x * 2
y = x.copy()
ax.fill_between(x, y_low, y_high, color="tab:blue", alpha=.5)
ax.plot(x, y, color="tab:red", lw=2, ls="--")

# diagnosing the figure
fig_diag = diagfig.diagnose_figure(fig)

Use of the decorator @diag_it:

import numpy as np
import matplotlib.pyplot as plt
from diagfig import diag_it

# creating a dummy figure in matplotlib
@diag_it()
def simple_plot()-> plt.Figure:
    fig, ax = plt.subplots()
    x = np.arange(10)
    y_low = x * .5
    y_high = x * 2
    y = x.copy()
    ax.fill_between(x, y_low, y_high, color="tab:blue", alpha=.5)
    ax.plot(x, y, color="tab:red", lw=2, ls="--")
    return fig

# diagnosing the figure
simple_plot()

Use of the matplotlib.figure.Figure custom subclass FigureDiag:

import numpy as np
import matplotlib.pyplot as plt
from diagfig import FigureDiag

# creating a dummy figure in matplotlib using the custom subclass of matplotlib.figure.Figure
fig, ax = plt.subplots(FigureClass=FigureDiag)
x = np.arange(10)
y_low = x * .5
y_high = x * 2
y = x.copy()
ax.fill_between(x, y_low, y_high, color="tab:blue", alpha=.5)
ax.plot(x, y, color="tab:red", lw=2, ls="--")

# diagnosing the figure
diaged_fig = fig.diag()

Output generated:

ExampleUse

References

  1. Lee, J., & Santos, W. P. dos. (2011). An Adaptive Fuzzy-Based System to Simulate, Quantify and Compensate Color Blindness. Integrated Computer-Aided Engineering, 18(1), 29–40. https://doi.org/10.3233/ICA-2011-0356

  2. Lindbloom, B. (2017. April 06). RGB Working Space Information. Retrieved 14 August 2024, from http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html

  3. LMS color space. (2024). In Wikipedia. Retrieved 14 August 2024, from https://en.wikipedia.org/w/index.php?title=LMS_color_space&oldid=1233434413#Hunt.2C_RLAB

  4. Viénot, F., Brettel, H., & Mollon, J. D. (1999). Digital video colourmaps for checking the legibility of displays by dichromats. Color Research & Application, 24(4), 243–252. https://doi.org/10.1002/(SICI)1520-6378(199908)24:4<243::AID-COL5>3.0.CO;2-3

  5. Ruminski, J., Bajorek, M., Ruminska, J., Wtorek, J., & Bujnowski, A. (2012). Computerized Color Processing for Dichromats. In Z. S. Hippe, J. L. Kulikowski, & T. Mroczek (Eds.), Human – Computer Systems Interaction: Backgrounds and Applications 2: Part 1 (pp. 453–470). Springer. https://doi.org/10.1007/978-3-642-23187-2_29

  6. Schmitz, J. (2016, August 28). Color Blindness Simulation Research. Ixora.Io. Retrieved 14 August 2024, from https://ixora.io/projects/colorblindness/color-blindness-simulation-research/

  7. Thakkar, S. (2024). Tsarjak/Simulate-Correct-ColorBlindness [Python]. https://github.com/tsarjak/Simulate-Correct-ColorBlindness (Original work published 2017)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diagfig-0.2.1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diagfig-0.2.1-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file diagfig-0.2.1.tar.gz.

File metadata

  • Download URL: diagfig-0.2.1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for diagfig-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b333d1ce247b02ad7b710ea6c6f6679ecc27af3f4078826244043c85bcc68ce2
MD5 2184703cbd9f32ac271613d39b8f25ff
BLAKE2b-256 71f467006b9381cdd2e3110475f8c7e434975f538a2354ae9204e14abc2d5d38

See more details on using hashes here.

File details

Details for the file diagfig-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: diagfig-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for diagfig-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae749eea87d66c198564042c38db7c1451e5182a5dab3b56830d26c91297b3b9
MD5 c9eb4c2907a9127fdb30eaeee674b25f
BLAKE2b-256 3137ab8ba680788de7c457871628941414d364734970b31dcde91d4f393edf43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page