Skip to content

Commit

Permalink
Merge pull request #3412 from neutrinoceros/pylab_must_die
Browse files Browse the repository at this point in the history
DOC: cleanup remaining occurences of pylab in favour of matplotlib.pyplot
  • Loading branch information
neutrinoceros authored Jul 7, 2021
2 parents be6c6b1 + ca477a0 commit 7cc5f89
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 51 deletions.
56 changes: 32 additions & 24 deletions doc/source/quickstart/4)_Data_Objects_and_Time_Series.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Data Objects and Time Series Data\n",
"\n",
"Just like before, we will load up yt. Since we'll be using pylab to plot some data in this notebook, we additionally tell matplotlib to place plots inline inside the notebook."
"Just like before, we will load up yt. Since we'll be using pyplot to plot some data in this notebook, we additionally tell matplotlib to place plots inline inside the notebook."
]
},
{
Expand All @@ -22,7 +22,7 @@
"%matplotlib inline\n",
"import yt\n",
"import numpy as np\n",
"from matplotlib import pylab"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down Expand Up @@ -91,13 +91,16 @@
},
"outputs": [],
"source": [
"pylab.semilogy(times, rho_ex[:,0], '-xk', label='Minimum')\n",
"pylab.semilogy(times, rho_ex[:,1], '-xr', label='Maximum')\n",
"pylab.ylabel(\"Density ($g/cm^3$)\")\n",
"pylab.xlabel(\"Time (Gyr)\")\n",
"pylab.legend()\n",
"pylab.ylim(1e-32, 1e-21)\n",
"pylab.show()"
"fig, ax = plt.subplots()\n",
"ax.set(\n",
" xlabel=\"Time (Gyr)\",\n",
" ylabel=\"Density ($g/cm^3$)\",\n",
" yscale=\"log\",\n",
" ylim=(1e-32, 1e-21),\n",
")\n",
"ax.plot(times, rho_ex[:,0], '-xk', label='Minimum')\n",
"ax.plot(times, rho_ex[:,1], '-xr', label='Maximum')\n",
"ax.legend()"
]
},
{
Expand Down Expand Up @@ -127,8 +130,9 @@
},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ray = ds.ray([0.1, 0.2, 0.3], [0.9, 0.8, 0.7])\n",
"pylab.semilogy(np.array(ray[\"t\"]), np.array(ray[\"density\"]))"
"ax.semilogy(np.array(ray[\"t\"]), np.array(ray[\"density\"]))"
]
},
{
Expand All @@ -141,7 +145,7 @@
},
"outputs": [],
"source": [
"print (ray[\"dts\"])"
"print(ray[\"dts\"])"
]
},
{
Expand All @@ -154,7 +158,7 @@
},
"outputs": [],
"source": [
"print (ray[\"t\"])"
"print(ray[\"t\"])"
]
},
{
Expand All @@ -167,7 +171,7 @@
},
"outputs": [],
"source": [
"print (ray[\"gas\", \"x\"])"
"print(ray[\"gas\", \"x\"])"
]
},
{
Expand All @@ -192,10 +196,10 @@
"ds = yt.load_sample(\"IsolatedGalaxy\")\n",
"v, c = ds.find_max((\"gas\", \"density\"))\n",
"sl = ds.slice(2, c[0])\n",
"print (sl[\"index\", \"x\"])\n",
"print (sl[\"index\", \"z\"])\n",
"print (sl[\"pdx\"])\n",
"print (sl[\"gas\", \"density\"].shape)"
"print(sl[\"index\", \"x\"])\n",
"print(sl[\"index\", \"z\"])\n",
"print(sl[\"pdx\"])\n",
"print(sl[\"gas\", \"density\"].shape)"
]
},
{
Expand All @@ -216,7 +220,7 @@
"outputs": [],
"source": [
"frb = sl.to_frb((50.0, 'kpc'), 1024)\n",
"print (frb[\"gas\", \"density\"].shape)"
"print(frb[\"gas\", \"density\"].shape)"
]
},
{
Expand Down Expand Up @@ -345,7 +349,7 @@
"outputs": [],
"source": [
"cg = ds.covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2**2)\n",
"print (cg[\"density\"].shape)"
"print(cg[\"density\"].shape)"
]
},
{
Expand All @@ -366,7 +370,7 @@
"outputs": [],
"source": [
"scg = ds.smoothed_covering_grid(2, [0.0, 0.0, 0.0], ds.domain_dimensions * 2**2)\n",
"print (scg[\"density\"].shape)"
"print(scg[\"density\"].shape)"
]
},
{
Expand All @@ -379,9 +383,13 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"name": "python3",
"display_name": "Python 3.9.5 64-bit ('yt-dev': pyenv)",
"metadata": {
"interpreter": {
"hash": "14363bd97bed451d1329fb3e06aa057a9e955a9421c5343dd7530f5497723a41"
}
}
},
"language_info": {
"codemirror_mode": {
Expand All @@ -393,7 +401,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
53 changes: 32 additions & 21 deletions doc/source/quickstart/5)_Derived_Fields_and_Profiles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import yt\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from yt import derived_field\n",
"from matplotlib import pylab"
"import yt\n",
"from yt import derived_field"
]
},
{
Expand Down Expand Up @@ -72,7 +72,7 @@
"source": [
"ds = yt.load_sample(\"IsolatedGalaxy\")\n",
"dd = ds.all_data()\n",
"print (list(dd.quantities.keys()))"
"print(list(dd.quantities.keys()))"
]
},
{
Expand All @@ -93,7 +93,7 @@
},
"outputs": [],
"source": [
"print (dd.quantities.extrema((\"gas\", \"dinosaurs\")))"
"print(dd.quantities.extrema((\"gas\", \"dinosaurs\")))"
]
},
{
Expand All @@ -114,7 +114,7 @@
},
"outputs": [],
"source": [
"print (dd.quantities.weighted_average_quantity((\"gas\", \"dinosaurs\"), weight=(\"gas\", \"temperature\")))"
"print(dd.quantities.weighted_average_quantity((\"gas\", \"dinosaurs\"), weight=(\"gas\", \"temperature\")))"
]
},
{
Expand All @@ -141,9 +141,9 @@
"bv = sp.quantities.bulk_velocity()\n",
"L = sp.quantities.angular_momentum_vector()\n",
"rho_min, rho_max = sp.quantities.extrema((\"gas\", \"density\"))\n",
"print (bv)\n",
"print (L)\n",
"print (rho_min, rho_max)"
"print(bv)\n",
"print(L)\n",
"print(rho_min, rho_max)"
]
},
{
Expand Down Expand Up @@ -172,9 +172,13 @@
"source": [
"prof = yt.Profile1D(sp, (\"gas\", \"density\"), 32, rho_min, rho_max, True, weight_field=(\"gas\", \"mass\"))\n",
"prof.add_fields([(\"gas\", \"temperature\"), (\"gas\", \"dinosaurs\")])\n",
"pylab.loglog(np.array(prof.x), np.array(prof[\"gas\", \"temperature\"]), \"-x\")\n",
"pylab.xlabel('Density $(g/cm^3)$')\n",
"pylab.ylabel('Temperature $(K)$')"
"\n",
"fig, ax = plt.subplots()\n",
"ax.loglog(np.array(prof.x), np.array(prof[\"gas\", \"temperature\"]), \"-x\")\n",
"ax.set(\n",
" xlabel='Density $(g/cm^3)$',\n",
" ylabel='Temperature $(K)$',\n",
")"
]
},
{
Expand All @@ -195,9 +199,12 @@
},
"outputs": [],
"source": [
"pylab.loglog(np.array(prof.x), np.array(prof[\"gas\", \"dinosaurs\"]), '-x')\n",
"pylab.xlabel('Density $(g/cm^3)$')\n",
"pylab.ylabel('Dinosaurs $(K cm / s)$')"
"fig, ax = plt.subplots()\n",
"ax.loglog(np.array(prof.x), np.array(prof[\"gas\", \"dinosaurs\"]), '-x')\n",
"ax.set(\n",
" xlabel='Density $(g/cm^3)$',\n",
" ylabel='Dinosaurs $(K cm / s)$',\n",
")"
]
},
{
Expand All @@ -220,9 +227,13 @@
"source": [
"prof = yt.Profile1D(sp, (\"gas\", \"density\"), 32, rho_min, rho_max, True, weight_field=None)\n",
"prof.add_fields([(\"gas\", \"mass\")])\n",
"pylab.loglog(np.array(prof.x), np.array(prof[\"gas\", \"mass\"].in_units(\"Msun\")), '-x')\n",
"pylab.xlabel('Density $(g/cm^3)$')\n",
"pylab.ylabel('Cell mass $(M_\\odot)$')"
"\n",
"fig, ax = plt.subplots()\n",
"ax.loglog(np.array(prof.x), np.array(prof[\"gas\", \"mass\"].in_units(\"Msun\")), '-x')\n",
"ax.set(\n",
" xlabel='Density $(g/cm^3)$',\n",
" ylabel='Cell mass $(M_\\odot)$',\n",
")"
]
},
{
Expand Down Expand Up @@ -278,9 +289,9 @@
"sp.set_field_parameter(\"bulk_velocity\", bv)\n",
"rv2 = sp.quantities.extrema((\"gas\", \"radial_velocity\"))\n",
"\n",
"print (bv)\n",
"print (rv1)\n",
"print (rv2)"
"print(bv)\n",
"print(rv1)\n",
"print(rv2)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/command-line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ or
yt load DD0030/DD0030
This will spawn ``iyt``, but the dataset given on the command line will
already be in the namespace as ``ds``. With interactive mode, you can use the
``pylab`` module to interactively plot.
already be in the namespace as ``ds``. With interactive mode, you can use
``matplotlib.pyplot`` to build plots interactively.

Command-line Functions
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion doc/source/visualizing/streamlines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ Example Script

.. code-block:: python
import matplotlib.pyplot as plt
import yt
from yt.visualization.api import Streamlines
ds = yt.load("DD1701") # Load ds
streamlines = Streamlines(ds, ds.domain_center)
streamlines.integrate_through_volume()
stream = streamlines.path(0)
matplotlib.pylab.semilogy(stream["t"], stream["gas", "density"], "-x")
plt.semilogy(stream["t"], stream["gas", "density"], "-x")
Running in Parallel
Expand Down
2 changes: 1 addition & 1 deletion doc/source/visualizing/unstructured_mesh_rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ file with a fixed camera position:

.. code-block:: python
import pylab as plt
import matplotlib.pyplot as plt
import yt
from yt.visualization.volume_rendering.api import MeshSource
Expand Down
2 changes: 1 addition & 1 deletion scripts/iyt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ except ImportError:
ip_shell = TerminalInteractiveShell(user_ns=namespace, banner1 = doc,
display_banner = True)
if "DISPLAY" in os.environ:
ip_shell.enable_pylab(import_all=False)
ip_shell.enable_matplotlib(import_all=False)


# The rest is a modified version of the IPython default profile code
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/volume_rendering/tests/test_vr_cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_interactive_camera(self):
log_fields=[False],
)
del cam
# Can't take a snapshot here since IC uses pylab.'
# Can't take a snapshot here since IC uses matplotlib.'

def test_projection_camera(self):
ds = self.ds
Expand Down

0 comments on commit 7cc5f89

Please sign in to comment.