{"id":9592,"library":"cmocean","title":"cmocean: Colormaps for Oceanography","description":"cmocean provides a collection of aesthetically pleasing and perceptually uniform colormaps specifically designed for oceanographic data visualization. It integrates seamlessly with Matplotlib. The current version is 4.0.3, and it receives active maintenance with frequent patch releases and less frequent major version updates.","status":"active","version":"4.0.3","language":"en","source_language":"en","source_url":"https://github.com/matplotlib/cmocean","tags":["colormap","oceanography","matplotlib","scientific-visualization","data-visualization"],"install":[{"cmd":"pip install cmocean","lang":"bash","label":"Install cmocean"}],"dependencies":[{"reason":"Essential for visualizing cmocean colormaps; cmocean provides the colormaps, but Matplotlib renders them.","package":"matplotlib","optional":false},{"reason":"Often used in conjunction with Matplotlib for data processing when generating plots, though not a strict dependency of cmocean itself.","package":"numpy","optional":true}],"imports":[{"note":"Colormaps are exposed via the `cm` submodule, not directly from the top-level package.","wrong":"import cmocean as cm","symbol":"cm","correct":"import cmocean.cm as cm"}],"quickstart":{"code":"import matplotlib.pyplot as plt\nimport cmocean.cm as cm\nimport numpy as np\n\n# Create some dummy data\ndata = np.random.rand(10, 10)\n\n# Plot using a cmocean colormap\nplt.imshow(data, cmap=cm.haline)\nplt.colorbar(label='Data Value')\nplt.title('Data with cmocean.haline Colormap')\n\n# To display the plot, uncomment the line below in an interactive environment\n# plt.show()\n\n# Save to a file if not in an interactive environment\n# plt.savefig('cmocean_example.png')\nplt.close() # Close plot to prevent display if running as script","lang":"python","description":"This quickstart demonstrates how to import a cmocean colormap (`cm.haline`) and use it with Matplotlib's `imshow` function to visualize a 2D array of data."},"warnings":[{"fix":"Always import `cmocean.cm` (e.g., `import cmocean.cm as cm`) and then reference colormaps as `cm.colormap_name`.","message":"cmocean colormaps are typically accessed through the `cmocean.cm` submodule. Attempting to directly access colormaps from the top-level `cmocean` module (e.g., `cmocean.haline`) will result in an `AttributeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `matplotlib` is installed (`pip install matplotlib`) and that your environment has a suitable backend for displaying plots (e.g., an interactive backend for GUI, or a non-interactive backend for saving figures).","message":"While `cmocean` provides colormaps, its practical utility relies entirely on `matplotlib` for rendering. If `matplotlib` is not installed or configured correctly, `cmocean` colormaps cannot be displayed or used effectively.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade `cmocean` to version `4.0.2` or newer (`pip install --upgrade cmocean`) to resolve issues with the `tools` module.","message":"In `cmocean` versions prior to `4.0.2`, a typo in the `cmocean.tools` module could cause issues when trying to retrieve certain colormaps using utility functions like `cmocean.tools.get_cmap()`. Direct access via `cmocean.cm.colormap_name` was unaffected.","severity":"gotcha","affected_versions":"<4.0.2"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Colormaps are stored in `cmocean.cm`. Use `cmocean.cm.haline` (or `cm.haline` if aliased `import cmocean.cm as cm`).","cause":"Attempting to access a colormap directly from the top-level `cmocean` module instead of its `cm` submodule.","error":"AttributeError: module 'cmocean' has no attribute 'haline'"},{"fix":"Ensure `matplotlib` is installed (`pip install matplotlib`). If running a script without an interactive display, use `plt.savefig('my_plot.png')` instead of `plt.show()` or configure a non-interactive backend like `matplotlib.use('Agg')`.","cause":"`matplotlib.pyplot` was imported, but a plotting function (like `plt.show()`) was called in an environment without a suitable graphical backend or `matplotlib` is not correctly installed.","error":"TypeError: 'NoneType' object is not callable (or similar error when trying to show a plot)"},{"fix":"Upgrade `cmocean` to version `4.0.2` or later: `pip install --upgrade cmocean`.","cause":"In `cmocean` versions prior to `4.0.2`, a typo in the `cmocean.tools` module prevented some colormaps from being correctly identified by the utility functions.","error":"KeyError: 'cmap_name' (when using cmocean.tools.get_cmap)"}]}