# 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
```bash
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`:
```python
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`:
```python
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`:
```python
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](https://github.com/vjtpons/diagfig/blob/main/example/example_use.png)
## 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)
Raw data
{
"_id": null,
"home_page": null,
"name": "diagfig",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "colourblind, black_and_white, figure, scientific_publication",
"author": null,
"author_email": "Vincent Pons <vincent.pons16@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/71/f4/67006b9381cdd2e3110475f8c7e434975f538a2354ae9204e14abc2d5d38/diagfig-0.2.1.tar.gz",
"platform": null,
"description": "# Diagfig\r\nA reviewer asked you for a b/w & colorblind friendly figure? `diagfig` can be used for a very simple visual checking.\r\n\r\n### Motivation and disclaimer\r\n\r\nThe 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.\r\n\r\nThis is by no mean my field of research, see references and docstrings for further information.\r\n\r\nOther 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.\r\n\r\n## Install the package\r\n\r\n```bash\r\npip install diagfig\r\n```\r\n\r\n## Examples of use\r\nThere are a few options for using `diagfig`. They are meant to help you to diagnose if a figure require color / quality adjustment before publication.\r\nIt can be used to simulate colorblindness on your figure as well as black and white.\r\nYou can also play with the dpi to combine effect of colorbliness and poor export quality.\r\nThe main options are:\r\n- `diagfig.diagnose_figure`: a function taking a figure as argument and returning a diagnosed figure.\r\n- `diagfig.diag_it`: a decorator automatically generating a diagnosed figure.\r\n- `diagfig.FigureDiag`: a subclass of `matpotlib.figure.Figure` with an additional `diag` method returning a \"diagnosed\" figure.\r\n\r\nUse of the main function `diagnose_figure`:\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport diagfig\r\n\r\n# creating a dummy figure in matplotlib\r\nfig, ax = plt.subplots()\r\nx = np.arange(10)\r\ny_low = x * .5\r\ny_high = x * 2\r\ny = x.copy()\r\nax.fill_between(x, y_low, y_high, color=\"tab:blue\", alpha=.5)\r\nax.plot(x, y, color=\"tab:red\", lw=2, ls=\"--\")\r\n\r\n# diagnosing the figure\r\nfig_diag = diagfig.diagnose_figure(fig)\r\n```\r\n\r\nUse of the decorator `@diag_it`:\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom diagfig import diag_it\r\n\r\n# creating a dummy figure in matplotlib\r\n@diag_it()\r\ndef simple_plot()-> plt.Figure:\r\n fig, ax = plt.subplots()\r\n x = np.arange(10)\r\n y_low = x * .5\r\n y_high = x * 2\r\n y = x.copy()\r\n ax.fill_between(x, y_low, y_high, color=\"tab:blue\", alpha=.5)\r\n ax.plot(x, y, color=\"tab:red\", lw=2, ls=\"--\")\r\n return fig\r\n\r\n# diagnosing the figure\r\nsimple_plot()\r\n```\r\n\r\nUse of the `matplotlib.figure.Figure` custom subclass `FigureDiag`:\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom diagfig import FigureDiag\r\n\r\n# creating a dummy figure in matplotlib using the custom subclass of matplotlib.figure.Figure\r\nfig, ax = plt.subplots(FigureClass=FigureDiag)\r\nx = np.arange(10)\r\ny_low = x * .5\r\ny_high = x * 2\r\ny = x.copy()\r\nax.fill_between(x, y_low, y_high, color=\"tab:blue\", alpha=.5)\r\nax.plot(x, y, color=\"tab:red\", lw=2, ls=\"--\")\r\n\r\n# diagnosing the figure\r\ndiaged_fig = fig.diag()\r\n```\r\n### Output generated:\r\n\r\n![ExampleUse](https://github.com/vjtpons/diagfig/blob/main/example/example_use.png)\r\n\r\n## References\r\n1. 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\u201340. https://doi.org/10.3233/ICA-2011-0356\r\n\r\n2. Lindbloom, B. (2017. April 06). RGB Working Space Information. Retrieved 14 August 2024, from http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html\r\n\r\n3. 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\r\n\r\n4. Vi\u00e9not, F., Brettel, H., & Mollon, J. D. (1999). Digital video colourmaps for checking the legibility of displays by dichromats. Color Research & Application, 24(4), 243\u2013252. https://doi.org/10.1002/(SICI)1520-6378(199908)24:4<243::AID-COL5>3.0.CO;2-3\r\n\r\n5. 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 \u2013 Computer Systems Interaction: Backgrounds and Applications 2: Part 1 (pp. 453\u2013470). Springer. https://doi.org/10.1007/978-3-642-23187-2_29\r\n\r\n6. 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/\r\n\r\n7. Thakkar, S. (2024). Tsarjak/Simulate-Correct-ColorBlindness [Python]. https://github.com/tsarjak/Simulate-Correct-ColorBlindness (Original work published 2017)\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Helpers to check if a figure is black and white and colourblind-friendly",
"version": "0.2.1",
"project_urls": {
"homepage": "https://github.com/vjtpons/diagfig"
},
"split_keywords": [
"colourblind",
" black_and_white",
" figure",
" scientific_publication"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3137ab8ba680788de7c457871628941414d364734970b31dcde91d4f393edf43",
"md5": "c9eb4c2907a9127fdb30eaeee674b25f",
"sha256": "ae749eea87d66c198564042c38db7c1451e5182a5dab3b56830d26c91297b3b9"
},
"downloads": -1,
"filename": "diagfig-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c9eb4c2907a9127fdb30eaeee674b25f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 1428969,
"upload_time": "2024-08-14T15:42:19",
"upload_time_iso_8601": "2024-08-14T15:42:19.244088Z",
"url": "https://files.pythonhosted.org/packages/31/37/ab8ba680788de7c457871628941414d364734970b31dcde91d4f393edf43/diagfig-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "71f467006b9381cdd2e3110475f8c7e434975f538a2354ae9204e14abc2d5d38",
"md5": "2184703cbd9f32ac271613d39b8f25ff",
"sha256": "b333d1ce247b02ad7b710ea6c6f6679ecc27af3f4078826244043c85bcc68ce2"
},
"downloads": -1,
"filename": "diagfig-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "2184703cbd9f32ac271613d39b8f25ff",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 1432754,
"upload_time": "2024-08-14T15:42:29",
"upload_time_iso_8601": "2024-08-14T15:42:29.058729Z",
"url": "https://files.pythonhosted.org/packages/71/f4/67006b9381cdd2e3110475f8c7e434975f538a2354ae9204e14abc2d5d38/diagfig-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-14 15:42:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "vjtpons",
"github_project": "diagfig",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "diagfig"
}