{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Demo CurveLinear Grid2\n\nCustom grid and ticklines.\n\nThis example demonstrates how to use GridHelperCurveLinear to define\ncustom grids and ticklines by applying a transformation on the grid.\nAs showcase on the plot, a 5x5 matrix is displayed on the Axes.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom mpl_toolkits.axisartist.axislines import Axes\nfrom mpl_toolkits.axisartist.grid_finder import (ExtremeFinderSimple,\n MaxNLocator)\nfrom mpl_toolkits.axisartist.grid_helper_curvelinear import \\\n GridHelperCurveLinear\n\n\ndef curvelinear_test1(fig):\n \"\"\"Grid for custom transform.\"\"\"\n\n def tr(x, y):\n return np.sign(x)*abs(x)**.5, y\n\n def inv_tr(x, y):\n return np.sign(x)*x**2, y\n\n grid_helper = GridHelperCurveLinear(\n (tr, inv_tr),\n extreme_finder=ExtremeFinderSimple(20, 20),\n # better tick density\n grid_locator1=MaxNLocator(nbins=6), grid_locator2=MaxNLocator(nbins=6))\n\n ax1 = fig.add_subplot(axes_class=Axes, grid_helper=grid_helper)\n # ax1 will have a ticks and gridlines defined by the given\n # transform (+ transData of the Axes). Note that the transform of the Axes\n # itself (i.e., transData) is not affected by the given transform.\n\n ax1.imshow(np.arange(25).reshape(5, 5),\n vmax=50, cmap=plt.cm.gray_r, origin=\"lower\")\n\n\nif __name__ == \"__main__\":\n fig = plt.figure(figsize=(7, 4))\n curvelinear_test1(fig)\n plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }