{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from matplotlib import pyplot\n", "from shapely.geometry import LineString\n", "%matplotlib inline\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "COLOR = {\n", " True: '#6699cc',\n", " False: '#ffcc33'\n", " }\n", "\n", "def v_color(ob):\n", " return COLOR[ob.is_simple]\n", "\n", "def plot_coords(ax, ob):\n", " x, y = ob.xy\n", " ax.plot(x, y, 'o', color='#999999', zorder=1)\n", "\n", "def plot_bounds(ax, ob):\n", " x, y = zip(*list((p.x, p.y) for p in ob.boundary))\n", " ax.plot(x, y, 'o', color='#000000', zorder=1)\n", "\n", "def plot_line(ax, ob):\n", " x, y = ob.xy\n", " ax.plot(x, y, color=v_color(ob), alpha=0.7, linewidth=3, solid_capstyle='round', zorder=2)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "fig = pyplot.figure(1, figsize=(12,20), dpi=90)\n", "\n", "# 1: simple line\n", "ax = fig.add_subplot(121)\n", "line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])\n", "\n", "plot_coords(ax, line)\n", "plot_bounds(ax, line)\n", "plot_line(ax, line)\n", "\n", "ax.set_title('a) simple')\n", "\n", "xrange = [-1, 4]\n", "yrange = [-1, 3]\n", "ax.set_xlim(*xrange)\n", "ax.set_ylim(*yrange)\n", "ax.set_yticks(list(range(*yrange)) + [yrange[-1]])\n", "ax.set_aspect(1)\n", "\n", "#2: complex line\n", "ax = fig.add_subplot(122)\n", "line2 = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (-1, 1), (1, 0)])\n", "\n", "plot_coords(ax, line2)\n", "plot_bounds(ax, line2)\n", "plot_line(ax, line2)\n", "\n", "ax.set_title('b) complex')\n", "\n", "xrange = [-2, 3]\n", "yrange = [-1, 3]\n", "ax.set_xlim(*xrange)\n", "ax.set_ylim(*yrange)\n", "ax.set_yticks(list(range(*yrange)) + [yrange[-1]])\n", "ax.set_aspect(1)\n", "\n", "pyplot.show()\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }