{ "info": { "author": "Joao Henry Huam\u00e1n Chinchay", "author_email": "joaohenry23@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "# Custom_colors_palette\nPython script to create a custom colors palette.\n\n# Requirements\n- Numpy\n- Matplotlib\n\n# Usage\nLet us suppose you have this satellite image of brightnes temperature (in Kelvin) and you want view it with a custom color palette.\n\n![](Images/example00.png)\n\n\nAn easy way to do this is by using the **custom_color_palette** package. Take a look at the following examples.\\\n\\\nFirst, let us import the packages and read the satellite image.\n```\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.colors as colors\nimport custom_color_palette as ccpl\n\nSatImg = np.fromfile('SatImage.bin', dtype='float32').reshape((800,1000))\n```\n\\\nThen, we called the **creates_palette** module from package alias (**ccpl**) and pass it two parameters. The first parameter is a list containing a sub-list with colors names and the second parameter is a list with the range of palette values.\nYou can use the matplotlib's colors names defined [here](https://matplotlib.org/examples/color/named_colors.html) or you can create your custom color palette using the Hex color code or the RGB color code, as seen in the following example.\n```\nmypalette, colorslabels = ccpl.creates_palette([['gold','orange','red','blue','cyan','#5A6673',(0/255, 0/255, 0/255)]], [180.0,330.0])\n```\n\\\nUse the outputs to set the norm parameter.\n```\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\n```\n\\\nThen create an array with the custom tickslabels and show de image. Do not forget you add spacing='proportional' to the colorbar.\n```\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example01', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example01.png)\n\\\n\\\nYou can also use the matplotlib's colors palette defined [here](https://matplotlib.org/tutorials/colors/colormaps.html) and custom it.\n```\nmypalette, colorslabels = ccpl.creates_palette([plt.cm.jet], [180.0,330.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example02', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example02.png)\n\\\n\\\nOn the other hand, if you want to merge your custom color palette with the Matplotlib's color palette, you can do it as follows.\n```\nmypalette, colorslabels = ccpl.creates_palette([['yellow','orange','red','darkred'], plt.cm.ocean_r], [180.0,250.0,330.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example03', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example03.png)\n\\\n\\\nIn addition to that, if you want your palette to have colors that do not change its tone, you can do it by adding sublists with the name of the color you want, as shown below.\n```\nmypalette, colorslabels = ccpl.creates_palette([['yellow','gold','red','darkred'], ['lime'], ['hotpink'], plt.cm.ocean_r], [180.0,250.0,255.0,260.0,330.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example04', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example04.png)\n\\\n\\\nIn the case you want to change the spacing between the colors, you can do it using **Increase** parameter. This parameter is optional and its default value is 1.0. The nexts lines show an example where add Increase=[1.0, 1.0, 5.0 5.0] in **creates_palette** with purpose of set the colors of each palette. In this example the spacing of the first colors palette is equal to 1, meanwhile the spacing of the last colors palette is equal to 5 (pay attention to colors bar).\n\nThe spacing of the Lime and Hot Pink colors were also defined (Lime equal to 1 and Hotpink equal to 5), however, even so, they show the same behavior because they are colors do not change their tone, for which spacing no have effect over they.\n```\nmypalette, colorslabels = ccpl.creates_palette([['yellow','gold','red','darkred'], ['lime'], ['hotpink'], plt.cm.ocean_r], [180.0,250.0,255.0,260.0,330.0], Increase=[1.0,1.0,5.0,5.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example05', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example05.png)\n\\\n\\\n\\\n**Advances options**\\\n\\\nIf you want to have more control over the custom color palette, you can get it using **EditPalette** parameter. This parameter permit define the range of color palette to then split it, selecting the colors region of palette that you want to use. Pay attention to next exemple.\\\nLet us imagine that we have a satellite image with black and white colors palette. \\\n![](Images/example06.png)\n\\\n\\\nNow, suppose we want values between 180.0 K and 240.0 K to have a custom color palette. We could do the following:\n```\nmypalette, colorslabels = ccpl.creates_palette([['maroon', 'red', 'darkorange', '#ffff00', 'forestgreen', 'cyan', 'royalblue', (148/255, 0/255, 211/255)], plt.cm.Greys], [180.0,240.0,330.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example07', figsize=(6,4), dpi=100)\nimg = plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example07.png)\n\\\n\\\nThis result is not bad, however the problem whit this is that the grey color palette was compacted, so we see colors with white tonalities above 240.0 K.\nOne way to solve this problem is to add **EditPalette** parameter to **creates_palette**. In the next exemple we add **EditPalette=[None,[180.0,330.0,240.0,330.0]]**. With the first element of this list (**None**) we are telling **creates_palette** that the first color palette will not be edited, while the second element (a sublist) tells its that the second color palette will be edited.\nThis sub-list have 4 values, the first and second values are used to define the range of colors palette, the third and fourth values are used to select the colors that we want to use. Using this parameter we notice that the colors above 240.0 K have grey tonalities and not white tonalities.\n```\nmypalette, colorslabels = ccpl.creates_palette([['maroon', 'red', 'darkorange', '#ffff00', 'forestgreen', 'cyan', 'royalblue', (148/255, 0/255, 211/255)], plt.cm.Greys], [180.0,240.0,330.0], EditPalette=[None,[180.0,330.0,240.0,330.0]])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example08', figsize=(6,4), dpi=100)\nimg=plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example08.png)\n\\\n\\\nFinally, if you wish, you could add **Increase** and use all the **creates_palette** parameters and create an image like the following (pay attention to grey's colors of bar):\n```\nmypalette, colorslabels = ccpl.creates_palette([['maroon', 'red', 'darkorange', '#ffff00', 'forestgreen', 'cyan', 'royalblue', (148/255, 0/255, 211/255)], plt.cm.Greys], [180.0,240.0,330.0], EditPalette=[None,[180.0,330.0,240.0,330.0]], Increase=[1.0,5.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example09', figsize=(6,4), dpi=100)\nimg=plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.show()\n\n```\n![](Images/example09.png)\n\\\n\\\nOr if you want:\n```\nmypalette, colorslabels = ccpl.creates_palette([['maroon', 'red', 'darkorange', '#ffff00', 'forestgreen', 'cyan', 'royalblue', (148/255, 0/255, 211/255)], plt.cm.Greys], [180.0,240.0,330.0], EditPalette=[None,[180.0,330.0,240.0,330.0]], Increase=[5.0,5.0])\n\nnorm = colors.BoundaryNorm(colorslabels, ncolors=mypalette.N)\ntickslabels = np.arange(180,340,10)\n\nfig = plt.figure('example10', figsize=(6,4), dpi=100)\nimg=plt.imshow(SatImg, cmap=mypalette, norm=norm)\ncbar = plt.colorbar(img, spacing='proportional', ticks=tickslabels)\ncbar.ax.set_yticklabels(tickslabels)\nplt.savefig('example10.png')\nplt.show()\n\n```\n![](Images/example10.png)\n\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/joaohenry23/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "custom-color-palette", "package_url": "https://pypi.org/project/custom-color-palette/", "platform": "", "project_url": "https://pypi.org/project/custom-color-palette/", "project_urls": { "Homepage": "https://github.com/joaohenry23/" }, "release_url": "https://pypi.org/project/custom-color-palette/0.0.1/", "requires_dist": [ "numpy", "matplotlib" ], "requires_python": ">=2.7", "summary": "Creates a custom color palette", "version": "0.0.1" }, "last_serial": 5850433, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d26a2314f68b7745a8466d5447c8955f", "sha256": "7aa1ab7ac3f3426e0807043802d5bce112ee1b37c6a86e783743a705f1becac2" }, "downloads": -1, "filename": "custom_color_palette-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d26a2314f68b7745a8466d5447c8955f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 6395, "upload_time": "2019-09-18T13:55:22", "url": "https://files.pythonhosted.org/packages/76/20/168cdeee4a10a4dd914a2e0161284b96454b80e1743d7f18e990cd52ea6b/custom_color_palette-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "132a71f48411905e6d8019f19e3bb87f", "sha256": "adffb0df990d4f6b49773880971861d42211fb152d22ab257e767739d0e9772d" }, "downloads": -1, "filename": "custom_color_palette-0.0.1.tar.gz", "has_sig": false, "md5_digest": "132a71f48411905e6d8019f19e3bb87f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 5341, "upload_time": "2019-09-18T13:55:25", "url": "https://files.pythonhosted.org/packages/a5/8d/6ec7aa5d1050fe1004a10e9d090a64a2f35d3ddc6eb9b03171c4b89f4ecf/custom_color_palette-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d26a2314f68b7745a8466d5447c8955f", "sha256": "7aa1ab7ac3f3426e0807043802d5bce112ee1b37c6a86e783743a705f1becac2" }, "downloads": -1, "filename": "custom_color_palette-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d26a2314f68b7745a8466d5447c8955f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7", "size": 6395, "upload_time": "2019-09-18T13:55:22", "url": "https://files.pythonhosted.org/packages/76/20/168cdeee4a10a4dd914a2e0161284b96454b80e1743d7f18e990cd52ea6b/custom_color_palette-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "132a71f48411905e6d8019f19e3bb87f", "sha256": "adffb0df990d4f6b49773880971861d42211fb152d22ab257e767739d0e9772d" }, "downloads": -1, "filename": "custom_color_palette-0.0.1.tar.gz", "has_sig": false, "md5_digest": "132a71f48411905e6d8019f19e3bb87f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 5341, "upload_time": "2019-09-18T13:55:25", "url": "https://files.pythonhosted.org/packages/a5/8d/6ec7aa5d1050fe1004a10e9d090a64a2f35d3ddc6eb9b03171c4b89f4ecf/custom_color_palette-0.0.1.tar.gz" } ] }