You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
452 lines
56 KiB
452 lines
56 KiB
2 years ago
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"___\n",
|
||
|
"\n",
|
||
|
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
|
||
|
"___\n",
|
||
|
"\n",
|
||
|
"# MATPLOTLIB\n",
|
||
|
"\n",
|
||
|
"----\n",
|
||
|
"## Matplotlib Basics"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Introduction"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Matplotlib is the \"grandfather\" library of data visualization with Python. It was created by John Hunter. He created it to try to replicate MatLab's (another programming language) plotting capabilities in Python. So if you happen to be familiar with matlab, matplotlib will feel natural to you.\n",
|
||
|
"\n",
|
||
|
"It is an excellent 2D and 3D graphics library for generating scientific figures. \n",
|
||
|
"\n",
|
||
|
"Some of the major Pros of Matplotlib are:\n",
|
||
|
"\n",
|
||
|
"* Generally easy to get started for simple plots\n",
|
||
|
"* Support for custom labels and texts\n",
|
||
|
"* Great control of every element in a figure\n",
|
||
|
"* High-quality output in many formats\n",
|
||
|
"* Very customizable in general\n",
|
||
|
"\n",
|
||
|
"Matplotlib allows you to create reproducible figures programmatically. Let's learn how to use it! Before continuing this lecture, I encourage you just to explore the official Matplotlib web page: http://matplotlib.org/\n",
|
||
|
"\n",
|
||
|
"## Installation \n",
|
||
|
"\n",
|
||
|
"If you are using our environment, its already installed for you. If you are not using our environment (not recommended), you'll need to install matplotlib first with either:\n",
|
||
|
"\n",
|
||
|
" conda install matplotlib\n",
|
||
|
"or\n",
|
||
|
"\n",
|
||
|
" pip install matplotlib\n",
|
||
|
" \n",
|
||
|
"## Importing"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Import the `matplotlib.pyplot` module under the name `plt` (the tidy way):"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# COMMON MISTAKE!\n",
|
||
|
"# DON'T FORGET THE .PYPLOT part\n",
|
||
|
"\n",
|
||
|
"import matplotlib.pyplot as plt"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**NOTE: If you are using an older version of jupyter, you need to run a \"magic\" command to see the plots inline with the notebook. Users of jupyter notebook 1.0 and above, don't need to run the cell below:**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"%matplotlib inline"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"**NOTE: For users running .py scripts in an IDE like PyCharm or Sublime Text Editor. You will not see the plots in a notebook, instead if you are using another editor, you'll use: *plt.show()* at the end of all your plotting commands to have the figure pop up in another window.**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"source": [
|
||
|
"# Basic Example\n",
|
||
|
"\n",
|
||
|
"Let's walk through a very simple example using two numpy arrays:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Basic Array Plot\n",
|
||
|
"\n",
|
||
|
"Let's walk through a very simple example using two numpy arrays. You can also use lists, but most likely you'll be passing numpy arrays or pandas columns (which essentially also behave like arrays).\n",
|
||
|
"\n",
|
||
|
"**The data we want to plot:**"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"x = np.arange(0,10)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"y = 2*x"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"x"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"y"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Using Matplotlib with plt.plot() function calls\n",
|
||
|
"\n",
|
||
|
"## Basic Matplotlib Commands\n",
|
||
|
"\n",
|
||
|
"We can create a very simple line plot using the following ( I encourage you to pause and use Shift+Tab along the way to check out the document strings for the functions we are using)."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3hUddrG8e9D772XEHovYgARC3bELrqKrl3RXV3Xd10FsWEHdS1rQ7GvbV0CgooirA07oJLQewm9CARCIOV5/5hhjXESQpjJSbk/15UrM+ecOefJiHPP75TnmLsjIiKSW7mgCxARkeJJASEiIhEpIEREJCIFhIiIRKSAEBGRiBQQIiISkQJCygwzG2tmdwaw3Y/M7LJ85r9qZvcXZU0iBaGAkBLBzI4ys2/MbIeZbTOzr82sT3je5Wb21YHW4e7Xuft9Ua7raDPbFf7ZbWae4/kuM4tz91Pd/bWDqfUgtu9m1i7XtFFm9ka0tiFlV4WgCxA5EDOrBXwA/Al4F6gEHA3sPYh1lHf3rGjX5u4zgBrhbcQDK4A67p4Z7W0VhVi9T1IyaQQhJUEHAHd/292z3H2Pu3/i7klm1hkYC/QPf2PfDv/bbfOcmU0xs93AcTl35ZjZQDNLMbObzWyTma03syv2b9DM6pvZ+2a208xmmtn9hf3mb2afm9nVedUaYfnTzexnM9seHjX1KMx2c6yvk5lNC4+8FpnZH3LMi/Q+VTazR81stZltDO+aq3ooNUjJpICQkmAxkGVmr5nZqWZWd/8Md18AXAd86+413L1OjtddBDwA1AQifbg3AWoDzYGrgGdyrPsZY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
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(x, y) \n",
|
||
|
"plt.xlabel('X Axis Title Here')\n",
|
||
|
"plt.ylabel('Y Axis Title Here')\n",
|
||
|
"plt.title('String Title Here')\n",
|
||
|
"plt.show() # Required for non-jupyter users , but also removes Out[] info"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Editing more figure parameters"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {
|
||
|
"scrolled": true
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3yV9fn/8dfFCHvvFfaQLYYhWPcWB6Kte4u2tlrbCigOLA5Q62i/WovbarWWgOJW3KKooJKEvfdGSAgJWdfvj3Pwl1IIITkn98k57+fjkQc559z3/blOgLzP/bnv+7rN3RERkcRVJegCREQkWAoCEZEEpyAQEUlwCgIRkQSnIBARSXAKAhGRBKcgkErPzJ40szsCGPddM7u8hNefN7N7KrImkbJQEEigzOwoM/vKzHaa2XYzm2lmA8OvXWFmXx5sG+5+vbtPiHBdvzCzXeGvbDPzYo93mVmyu5/m7i8cSq2HML6bWZd9nhtvZi9FagyRvaoFXYAkLjOrD7wF/Bp4DUgCfgHsOYRtVHX3wkjX5u5fAHXDY3QAVgAN3b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ZpnDV14gJdOiNaYIiIACzZkMiY1jbS1Ozm5ZwsmnNObFvXjp0lcpMXswWIRkUO1p6CQxz9eyhOfLqNh7eo8ftEATu/TUnsBB6EgEJG4MGfVT4xJTWPp5l2cO6ANd5zRk0Zx2iQu0hQEIlKp7c4r4MH3F/H8VytpVb8mz105kOO66xKlQ6EgEJFK68slWxk7NY21P+Vw2ZHtGX1qD+rW0K+1Q6WfmIhUOjtz8rn37fm8NnstnZrW4bX
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(x, y) \n",
|
||
|
"plt.xlabel('X Axis Title Here')\n",
|
||
|
"plt.ylabel('Y Axis Title Here')\n",
|
||
|
"plt.title('String Title Here')\n",
|
||
|
"plt.xlim(0,6) # Lower Limit, Upper Limit\n",
|
||
|
"plt.ylim(0,12) # Lower Limit, Upper Limit\n",
|
||
|
"plt.show() # Required for non-jupyter users , but also removes Out[] info"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Exporting a plot"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Help on function savefig in module matplotlib.pyplot:\n",
|
||
|
"\n",
|
||
|
"savefig(*args, **kwargs)\n",
|
||
|
" Save the current figure.\n",
|
||
|
" \n",
|
||
|
" Call signature::\n",
|
||
|
" \n",
|
||
|
" savefig(fname, dpi=None, facecolor='w', edgecolor='w',\n",
|
||
|
" orientation='portrait', papertype=None, format=None,\n",
|
||
|
" transparent=False, bbox_inches=None, pad_inches=0.1,\n",
|
||
|
" frameon=None, metadata=None)\n",
|
||
|
" \n",
|
||
|
" The output formats available depend on the backend being used.\n",
|
||
|
" \n",
|
||
|
" Parameters\n",
|
||
|
" ----------\n",
|
||
|
" \n",
|
||
|
" fname : str or PathLike or file-like object\n",
|
||
|
" A path, or a Python file-like object, or\n",
|
||
|
" possibly some backend-dependent object such as\n",
|
||
|
" `matplotlib.backends.backend_pdf.PdfPages`.\n",
|
||
|
" \n",
|
||
|
" If *format* is not set, then the output format is inferred from\n",
|
||
|
" the extension of *fname*, if any, and from :rc:`savefig.format`\n",
|
||
|
" otherwise. If *format* is set, it determines the output format.\n",
|
||
|
" \n",
|
||
|
" Hence, if *fname* is not a path or has no extension, remember to\n",
|
||
|
" specify *format* to ensure that the correct backend is used.\n",
|
||
|
" \n",
|
||
|
" Other Parameters\n",
|
||
|
" ----------------\n",
|
||
|
" \n",
|
||
|
" dpi : [ *None* | scalar > 0 | 'figure' ]\n",
|
||
|
" The resolution in dots per inch. If *None*, defaults to\n",
|
||
|
" :rc:`savefig.dpi`. If 'figure', uses the figure's dpi value.\n",
|
||
|
" \n",
|
||
|
" quality : [ *None* | 1 <= scalar <= 100 ]\n",
|
||
|
" The image quality, on a scale from 1 (worst) to 95 (best).\n",
|
||
|
" Applicable only if *format* is jpg or jpeg, ignored otherwise.\n",
|
||
|
" If *None*, defaults to :rc:`savefig.jpeg_quality` (95 by default).\n",
|
||
|
" Values above 95 should be avoided; 100 completely disables the\n",
|
||
|
" JPEG quantization stage.\n",
|
||
|
" \n",
|
||
|
" optimize : bool\n",
|
||
|
" If *True*, indicates that the JPEG encoder should make an extra\n",
|
||
|
" pass over the image in order to select optimal encoder settings.\n",
|
||
|
" Applicable only if *format* is jpg or jpeg, ignored otherwise.\n",
|
||
|
" Is *False* by default.\n",
|
||
|
" \n",
|
||
|
" progressive : bool\n",
|
||
|
" If *True*, indicates that this image should be stored as a\n",
|
||
|
" progressive JPEG file. Applicable only if *format* is jpg or\n",
|
||
|
" jpeg, ignored otherwise. Is *False* by default.\n",
|
||
|
" \n",
|
||
|
" facecolor : color spec or None, optional\n",
|
||
|
" The facecolor of the figure; if *None*, defaults to\n",
|
||
|
" :rc:`savefig.facecolor`.\n",
|
||
|
" \n",
|
||
|
" edgecolor : color spec or None, optional\n",
|
||
|
" The edgecolor of the figure; if *None*, defaults to\n",
|
||
|
" :rc:`savefig.edgecolor`\n",
|
||
|
" \n",
|
||
|
" orientation : {'landscape', 'portrait'}\n",
|
||
|
" Currently only supported by the postscript backend.\n",
|
||
|
" \n",
|
||
|
" papertype : str\n",
|
||
|
" One of 'letter', 'legal', 'executive', 'ledger', 'a0' through\n",
|
||
|
" 'a10', 'b0' through 'b10'. Only supported for postscript\n",
|
||
|
" output.\n",
|
||
|
" \n",
|
||
|
" format : str\n",
|
||
|
" The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when\n",
|
||
|
" this is unset is documented under *fname*.\n",
|
||
|
" \n",
|
||
|
" transparent : bool\n",
|
||
|
" If *True*, the axes patches will all be transparent; the\n",
|
||
|
" figure patch will also be transparent unless facecolor\n",
|
||
|
" and/or edgecolor are specified via kwargs.\n",
|
||
|
" This is useful, for example, for displaying\n",
|
||
|
" a plot on top of a colored background on a web page. The\n",
|
||
|
" transparency of these patches will be restored to their\n",
|
||
|
" original values upon exit of this function.\n",
|
||
|
" \n",
|
||
|
" bbox_inches : str or `~matplotlib.transforms.Bbox`, optional\n",
|
||
|
" Bbox in inches. Only the given portion of the figure is\n",
|
||
|
" saved. If 'tight', try to figure out the tight bbox of\n",
|
||
|
" the figure. If None, use savefig.bbox\n",
|
||
|
" \n",
|
||
|
" pad_inches : scalar, optional\n",
|
||
|
" Amount of padding around the figure when bbox_inches is\n",
|
||
|
" 'tight'. If None, use savefig.pad_inches\n",
|
||
|
" \n",
|
||
|
" bbox_extra_artists : list of `~matplotlib.artist.Artist`, optional\n",
|
||
|
" A list of extra artists that will be considered when the\n",
|
||
|
" tight bbox is calculated.\n",
|
||
|
" \n",
|
||
|
" metadata : dict, optional\n",
|
||
|
" Key/value pairs to store in the image metadata. The supported keys\n",
|
||
|
" and defaults depend on the image format and backend:\n",
|
||
|
" \n",
|
||
|
" - 'png' with Agg backend: See the parameter ``metadata`` of\n",
|
||
|
" `~.FigureCanvasAgg.print_png`.\n",
|
||
|
" - 'pdf' with pdf backend: See the parameter ``metadata`` of\n",
|
||
|
" `~.backend_pdf.PdfPages`.\n",
|
||
|
" - 'eps' and 'ps' with PS backend: Only 'Creator' is supported.\n",
|
||
|
" \n",
|
||
|
" pil_kwargs : dict, optional\n",
|
||
|
" Additional keyword arguments that are passed to `PIL.Image.save`\n",
|
||
|
" when saving the figure. Only applicable for formats that are saved\n",
|
||
|
" using Pillow, i.e. JPEG, TIFF, and (if the keyword is set to a\n",
|
||
|
" non-None value) PNG.\n",
|
||
|
"\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"help(plt.savefig)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXhUhdn+8e/DTtj3PQRkXxUCiLjihriLVq2vWpeifevb9m2rIG6449JWq60K7q9bWwKCiAq4Unegko2whS0ECDuBELI9vz+S/hppYkNmwpnM3J/r8srMOSdzbkZy53Bm5jnm7oiISPSqE3QAERGpWSp6EZEop6IXEYlyKnoRkSinohcRiXL1gg5QkbZt23pCQkLQMUREao2lS5fucPd2Fa2LyKJPSEhgyZIlQccQEak1zGxDZet06kZEJMqp6EVEopyKXk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IhNZ88L8nc/XoBJV8LfMfj+jd/TMzSzhs2YJyd78CLg1vLBEJUmFxCdM/y+TJRauJa1iX3/9oKBcf10VDyGqpcJyjvx74SyXrHFhgZg485+7Tw7A/EalBqZv3cuvMZFZs2ce5Qzox9fyBtGvWMOhYEoKQit7M7gCKgNcr2WSMu2ebWXtgoZlluPtnlTzWRGAiQHx8fCixRKQa8guLeWLRamYszqR1kwY8d/Vwzh7YMehYEgbVLnozu5bSF2lPd3evaBt3zy77mmNms4GRQIVFX3a0Px0gMTGxwscTkZrxzbpdTE5KJnPHAS5P7MaU8f1pEVc/6FgSJtUqejMbB0wCTnH3vEq2aQLUcffcsttnAfdVO6mIhF1ufiG
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(x,y)\n",
|
||
|
"plt.savefig('example.png')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"---------------------\n",
|
||
|
"\n",
|
||
|
"--------------------"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"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.7.4"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 1
|
||
|
}
|