initial upload

This commit is contained in:
2025-10-21 11:20:44 +08:00
parent ad1b18ba06
commit 4333398dbe
131 changed files with 124404 additions and 0 deletions

2
.gitignore vendored
View File

@@ -12,3 +12,5 @@ ipython_config.py
# Remove previous ipynb_checkpoints # Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/ # git rm -r .ipynb_checkpoints/
.DS_Store
misc/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "67bafe91-e2ec-44b7-ba59-21854113bea2",
"metadata": {},
"outputs": [],
"source": [
"import pyvista as pv\n",
"\n",
"pv.set_jupyter_backend('trame')\n",
"mesh = pv.read(\"tempRes.vtk\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ce7c06c7-6178-48b3-9449-1af124d45125",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ed0e6aebb0284b81923e89f18067e6bf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Widget(value='<iframe src=\"http://localhost:59556/index.html?ui=P_0x15d960230_0&reconnect=auto\" class=\"pyvista…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"pl = pv.Plotter()\n",
"pl.add_mesh(mesh)\n",
"pl.show() "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3776bb78-f64a-41a8-8b65-3ff31d4dabb3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (forward_modeling)",
"language": "python",
"name": "forward_modeling"
},
"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.12.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

35
scientific-computing-1/.gitignore vendored Normal file
View File

@@ -0,0 +1,35 @@
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject

View File

@@ -0,0 +1,643 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to scientific computing with Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"J.R. Johansson (jrjohansson at gmail.com)\n",
"\n",
"The latest version of this [IPython notebook](http://ipython.org/notebook.html) lecture is available at [http://github.com/jrjohansson/scientific-python-lectures](http://github.com/jrjohansson/scientific-python-lectures).\n",
"\n",
"The other notebooks in this lecture series are indexed at [http://jrjohansson.github.io](http://jrjohansson.github.io)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The role of computing in science"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Science has traditionally been divided into experimental and theoretical disciplines, but during the last several decades computing has emerged as a very important part of science. Scientific computing is often closely related to theory, but it also has many characteristics in common with experimental work. It is therefore often viewed as a new third branch of science. In most fields of science, computational work is an important complement to both experiments and theory, and nowadays a vast majority of both experimental and theoretical papers involve some numerical calculations, simulations or computer modeling.\n",
"<center>\n",
"<img src=\"images/theory-experiment-computation.png\" width=\"300\">\n",
"</center>\n",
"\n",
"In experimental and theoretical sciences there are well established codes of conducts for how results and methods are published and made available to other scientists. For example, in theoretical sciences, derivations, proofs and other results are published in full detail, or made available upon request. Likewise, in experimental sciences, the methods used and the results are published, and all experimental data should be available upon request. It is considered unscientific to withhold crucial details in a theoretical proof or experimental method, that would hinder other scientists from replicating and reproducing the results.\n",
"\n",
"In computational sciences there are not yet any well established guidelines for how source code and generated data should be handled. For example, it is relatively rare that source code used in simulations for published papers are provided to readers, in contrast to the open nature of experimental and theoretical work. And it is not uncommon that source code for simulation software is withheld and considered a competitive advantage (or unnecessary to publish). \n",
"\n",
"However, this issue has recently started to attract increasing attention, and a number of editorials in high-profile journals have called for increased openness in computational sciences. Some prestigious journals, including Science, have even started to demand of authors to provide the source code for simulation software used in publications to readers upon request. \n",
"\n",
"Discussions are also ongoing on how to facilitate distribution of scientific software, for example as supplementary materials to scientific papers."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### References"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" * [Reproducible Research in Computational Science](http://dx.doi.org/10.1126/science.1213847), Roger D. Peng, Science 334, 1226 (2011).\n",
"\n",
" * [Shining Light into Black Boxes](http://dx.doi.org/10.1126/science.1218263), A. Morin et al., Science 336, 159-160 (2012).\n",
" \n",
" * [The case for open computer programs](http://dx.doi.org/doi:10.1038/nature10836), D.C. Ince, Nature 482, 485 (2012)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Requirements on scientific computing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Replication** and **reproducibility** are two of the cornerstones in the scientific method. With respect to numerical work, complying with these concepts have the following practical implications:\n",
"\n",
"* Replication: An author of a scientific paper that involves numerical calculations should be able to rerun the simulations and replicate the results upon request. Other scientist should also be able to perform the same calculations and obtain the same results, given the information about the methods used in a publication.\n",
"\n",
"* Reproducibility: The results obtained from numerical simulations should be reproducible with an independent implementation of the method, or using a different method altogether. \n",
"\n",
"\n",
"In summary: A sound scientific result should be reproducible, and a sound scientific study should be replicable.\n",
"\n",
"\n",
"To achieve these goals, we need to:\n",
"\n",
"* Keep and take note of *exactly* which source code and version that was used to produce data and figures in published papers.\n",
"\n",
"* Record information of which version of external software that was used. Keep access to the environment that was used.\n",
"\n",
"* Make sure that old codes and notes are backed up and kept for future reference. \n",
"\n",
"* Be ready to give additional information about the methods used, and perhaps also the simulation codes, to an interested reader who requests it (even years after the paper was published!).\n",
"\n",
"* Ideally codes should be published online, to make it easier for other scientists interested in the codes to access it."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Tools for managing source code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ensuring replicability and reproducibility of scientific simulations is a *complicated problem*, but there are good tools to help with this:\n",
"\n",
"* Revision Control System (RCS) software. \n",
" * Good choices include:\n",
" * git - http://git-scm.com\n",
" * mercurial - http://mercurial.selenic.com. Also known as `hg`.\n",
" * subversion - http://subversion.apache.org. Also known as `svn`.\n",
"\n",
"* Online repositories for source code. Available as both private and public repositories. \n",
" * Some good alternatives are\n",
" * Github - http://www.github.com\n",
" * Bitbucket - http://www.bitbucket.com\n",
" * Privately hosted repositories on the university's or department's servers.\n",
"\n",
"#### Note\n",
"\t\n",
"Repositories are also excellent for version controlling manuscripts, figures, thesis files, data files, lab logs, etc. Basically for any digital content that must be preserved and is frequently updated. Again, both public and private repositories are readily available. They are also excellent collaboration tools!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What is Python?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Python](http://www.python.org/) is a modern, general-purpose, object-oriented, high-level programming language.\n",
"\n",
"General characteristics of Python:\n",
"\n",
"* **clean and simple language:** Easy-to-read and intuitive code, easy-to-learn minimalistic syntax, maintainability scales well with size of projects.\n",
"* **expressive language:** Fewer lines of code, fewer bugs, easier to maintain.\n",
"\n",
"Technical details:\n",
"\n",
"* **dynamically typed:** No need to define the type of variables, function arguments or return types.\n",
"* **automatic memory management:** No need to explicitly allocate and deallocate memory for variables and data arrays. No memory leak bugs. \n",
"* **interpreted:** No need to compile the code. The Python interpreter reads and executes the python code directly.\n",
"\n",
"Advantages:\n",
"\n",
"* The main advantage is ease of programming, minimizing the time required to develop, debug and maintain the code.\n",
"* Well designed language that encourage many good programming practices:\n",
" * Modular and object-oriented programming, good system for packaging and re-use of code. This often results in more transparent, maintainable and bug-free code.\n",
" * Documentation tightly integrated with the code.\n",
"* A large standard library, and a large collection of add-on packages.\n",
"\n",
"Disadvantages:\n",
"\n",
"* Since Python is an interpreted and dynamically typed programming language, the execution of python code can be slow compared to compiled statically typed programming languages, such as C and Fortran. \n",
"* Somewhat decentralized, with different environment, packages and documentation spread out at different places. Can make it harder to get started."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What makes python suitable for scientific computing?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"./images/optimizing-what.png\" width=\"600\">\n",
"\n",
"* Python has a strong position in scientific computing: \n",
" * Large community of users, easy to find help and documentation.\n",
"\n",
"* Extensive ecosystem of scientific libraries and environments\n",
" * numpy: http://numpy.scipy.org - Numerical Python\n",
" * scipy: http://www.scipy.org - Scientific Python\n",
" * matplotlib: http://www.matplotlib.org - graphics library\n",
"\n",
"* Great performance due to close integration with time-tested and highly optimized codes written in C and Fortran:\n",
" * blas, atlas blas, lapack, arpack, Intel MKL, ...\n",
"\n",
"* Good support for \n",
" * Parallel processing with processes and threads\n",
" * Interprocess communication (MPI)\n",
" * GPU computing (OpenCL and CUDA)\n",
"\n",
"* Readily available and suitable for use on high-performance computing clusters. \n",
"\n",
"* No license costs, no unnecessary use of research budget.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The scientific python software stack"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- <img src=\"./images/scientific-python-stack.svg\" width=\"300\"> -->\n",
"<img src=\"./images/scientific-python-stack.png\" width=\"300\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python environments"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Python is not only a programming language, but often also refers to the standard implementation of the interpreter (technically referred to as [CPython](http://en.wikipedia.org/wiki/CPython)) that actually runs the python code on a computer.\n",
"\n",
"There are also many different environments through which the python interpreter can be used. Each environment has different advantages and is suitable for different workflows. One strength of python is that it is versatile and can be used in complementary ways, but it can be confusing for beginners so we will start with a brief survey of python environments that are useful for scientific computing."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python interpreter"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The standard way to use the Python programming language is to use the Python interpreter to run python code. The python interpreter is a program that reads and execute the python code in files passed to it as arguments. At the command prompt, the command ``python`` is used to invoke the Python interpreter.\n",
"\n",
"For example, to run a file ``my-program.py`` that contains python code from the command prompt, use::\n",
"\n",
" $ python my-program.py\n",
"\n",
"We can also start the interpreter by simply typing ``python`` at the command line, and interactively type python code into the interpreter. \n",
"\n",
"<!-- <img src=\"files/images/python-screenshot.jpg\" width=\"600\"> -->\n",
"<img src=\"./images/python-screenshot.jpg\" width=\"600\">\n",
"\n",
"\n",
"This is often how we want to work when developing scientific applications, or when doing small calculations. But the standard python interpreter is not very convenient for this kind of work, due to a number of limitations."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### IPython"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"IPython is an interactive shell that addresses the limitation of the standard python interpreter, and it is a work-horse for scientific use of python. It provides an interactive prompt to the python interpreter with a greatly improved user-friendliness.\n",
"\n",
"<!-- <img src=\"./images/ipython-screenshot.jpg\" width=\"600\"> -->\n",
"<img src=\"./images/ipython-screenshot.jpg\" width=\"600\">\n",
"\n",
"Some of the many useful features of IPython includes:\n",
"\n",
"* Command history, which can be browsed with the up and down arrows on the keyboard.\n",
"* Tab auto-completion.\n",
"* In-line editing of code.\n",
"* Object introspection, and automatic extract of documentation strings from python objects like classes and functions.\n",
"* Good interaction with operating system shell.\n",
"* Support for multiple parallel back-end processes, that can run on computing clusters or cloud services like Amazon EC2.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### IPython notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[IPython notebook](http://ipython.org/notebook.html) is an HTML-based notebook environment for Python, similar to Mathematica or Maple. It is based on the IPython shell, but provides a cell-based environment with great interactivity, where calculations can be organized and documented in a structured way.\n",
"\n",
"<!-- <img src=\"./images/ipython-notebook-screenshot.jpg\" width=\"800\"> -->\n",
"<img src=\"./images/ipython-notebook-screenshot.jpg\" width=\"800\">\n",
"\n",
"Although using a web browser as graphical interface, IPython notebooks are usually run locally, from the same computer that run the browser. To start a new IPython notebook session, run the following command:\n",
"\n",
" $ ipython notebook\n",
"\n",
"from a directory where you want the notebooks to be stored. This will open a new browser window (or a new tab in an existing window) with an index page where existing notebooks are shown and from which new notebooks can be created."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Spyder"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Spyder](http://code.google.com/p/spyderlib/) is a MATLAB-like IDE for scientific computing with python. It has the many advantages of a traditional IDE environment, for example that everything from code editing, execution and debugging is carried out in a single environment, and work on different calculations can be organized as projects in the IDE environment.\n",
"\n",
"<!-- <img src=\"./images/spyder-screenshot.jpg\" width=\"800\"> -->\n",
"<img src=\"./images/spyder-screenshot.jpg\" width=\"800\">\n",
"\n",
"Some advantages of Spyder:\n",
"\n",
"* Powerful code editor, with syntax high-lighting, dynamic code introspection and integration with the python debugger.\n",
"* Variable explorer, IPython command prompt.\n",
"* Integrated documentation and help."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Versions of Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are currently two versions of python: Python 2 and Python 3. Python 3 will eventually supersede Python 2, but it is not backward-compatible with Python 2. A lot of existing python code and packages has been written for Python 2, and it is still the most wide-spread version. For these lectures either version will be fine, but it is probably easier to stick with Python 2 for now, because it is more readily available via prebuilt packages and binary installers.\n",
"\n",
"To see which version of Python you have, run\n",
" \n",
" $ python --version\n",
" Python 2.7.3\n",
" $ python3.2 --version\n",
" Python 3.2.3\n",
"\n",
"Several versions of Python can be installed in parallel, as shown above.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Conda"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The best way to set-up a scientific Python environment is to use the cross-platform package manager `conda` from Continuum Analytics. First download and install miniconda http://conda.pydata.org/miniconda.html or Anaconda (see below). Next, to install the required libraries for these notebooks, simply run:\n",
"\n",
" $ conda install ipython ipython-notebook spyder numpy scipy sympy matplotlib cython\n",
"\n",
"This should be sufficient to get a working environment on any platform supported by `conda`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Linux"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In Ubuntu Linux, to installing python and all the requirements run:\n",
"\n",
" $ sudo apt-get install python ipython ipython-notebook\n",
"$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sympy\n",
" $ sudo apt-get install spyder"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### MacOS X"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Macports*\n",
"\n",
"Python is included by default in Mac OS X, but for our purposes it will be useful to install a new python environment using [Macports](http://www.macports.org/), because it makes it much easier to install all the required additional packages. Using Macports, we can install what we need with:\n",
"\n",
" $ sudo port install py27-ipython +pyside+notebook+parallel+scientific\n",
" $ sudo port install py27-scipy py27-matplotlib py27-sympy\n",
" $ sudo port install py27-spyder\n",
"\n",
"These will associate the commands `python` and `ipython` with the versions installed via macports (instead of the one that is shipped with Mac OS X), run the following commands:\n",
"\n",
" $ sudo port select python python27\n",
" $ sudo port select ipython ipython27\n",
"\n",
"*Fink*\n",
"\n",
"Or, alternatively, you can use the [Fink](http://www.finkproject.org/) package manager. After installing Fink, use the following command to install python and the packages that we need:\n",
"\n",
" $ sudo fink install python27 ipython-py27 numpy-py27 matplotlib-py27 scipy-py27 sympy-py27\n",
" $ sudo fink install spyder-mac-py27"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Windows"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Windows lacks a good packaging system, so the easiest way to setup a Python environment is to install a pre-packaged distribution. Some good alternatives are:\n",
"\n",
" * [Enthought Python Distribution](http://www.enthought.com/products/epd.php). EPD is a commercial product but is available free for academic use.\n",
" * [Anaconda](http://continuum.io/downloads.html). The Anaconda Python distribution comes with many scientific computing and data science packages and is free, including for commercial use and redistribution. It also has add-on products such as Accelerate, IOPro, and MKL Optimizations, which have free trials and are free for academic use.\n",
" * [Python(x,y)](http://code.google.com/p/pythonxy/). Fully open source.\n",
"\n",
"\n",
"\n",
"#### Note\n",
"\n",
"EPD and Anaconda are also available for Linux and Max OS X."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Further reading"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" * [Python](http://www.python.org). The official Python web site.\n",
" * [Python tutorials](http://docs.python.org/2/tutorial). The official Python tutorials.\n",
" * [Think Python](http://www.greenteapress.com/thinkpython). A free book on Python."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python and module versions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since there are several different versions of Python and each Python package has its own release cycle and version number (for example scipy, numpy, matplotlib, etc., which we installed above and will discuss in detail in the following lectures), it is important for the reproducibility of an IPython notebook to record the versions of all these different software packages. If this is done properly it will be easy to reproduce the environment that was used to run a notebook, but if not it can be hard to know what was used to produce the results in a notebook.\n",
"\n",
"To encourage the practice of recording Python and module versions in notebooks, I've created a simple IPython extension that produces a table with versions numbers of selected software components. I believe that it is a good practice to include this kind of table in every notebook you create. \n",
"\n",
"To install this IPython extension, use `pip install version_information`:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting version-information\n",
"Installing collected packages: version-information\n",
"Successfully installed version-information-1.0.3\n"
]
}
],
"source": [
"# you only need to do this once\n",
"!pip install --upgrade version_information"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"or alternatively run (deprecated method):"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"# you only need to do this once\n",
"%install_ext http://raw.github.com/jrjohansson/version_information/master/version_information.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, to load the extension and produce the version table"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"application/json": {
"Software versions": [
{
"module": "Python",
"version": "2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]"
},
{
"module": "IPython",
"version": "3.2.1"
},
{
"module": "OS",
"version": "Darwin 14.1.0 x86_64 i386 64bit"
},
{
"module": "numpy",
"version": "1.9.2"
},
{
"module": "scipy",
"version": "0.16.0"
},
{
"module": "matplotlib",
"version": "1.4.3"
},
{
"module": "sympy",
"version": "0.7.6"
},
{
"module": "version_information",
"version": "1.0.3"
}
]
},
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]</td></tr><tr><td>IPython</td><td>3.2.1</td></tr><tr><td>OS</td><td>Darwin 14.1.0 x86_64 i386 64bit</td></tr><tr><td>numpy</td><td>1.9.2</td></tr><tr><td>scipy</td><td>0.16.0</td></tr><tr><td>matplotlib</td><td>1.4.3</td></tr><tr><td>sympy</td><td>0.7.6</td></tr><tr><td>version_information</td><td>1.0.3</td></tr><tr><td colspan='2'>Sat Aug 15 10:38:48 2015 JST</td></tr></table>"
],
"text/latex": [
"\\begin{tabular}{|l|l|}\\hline\n",
"{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
"Python & 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)] \\\\ \\hline\n",
"IPython & 3.2.1 \\\\ \\hline\n",
"OS & Darwin 14.1.0 x86\\_64 i386 64bit \\\\ \\hline\n",
"numpy & 1.9.2 \\\\ \\hline\n",
"scipy & 0.16.0 \\\\ \\hline\n",
"matplotlib & 1.4.3 \\\\ \\hline\n",
"sympy & 0.7.6 \\\\ \\hline\n",
"version_information & 1.0.3 \\\\ \\hline\n",
"\\hline \\multicolumn{2}{|l|}{Sat Aug 15 10:38:48 2015 JST} \\\\ \\hline\n",
"\\end{tabular}\n"
],
"text/plain": [
"Software versions\n",
"Python 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]\n",
"IPython 3.2.1\n",
"OS Darwin 14.1.0 x86_64 i386 64bit\n",
"numpy 1.9.2\n",
"scipy 0.16.0\n",
"matplotlib 1.4.3\n",
"sympy 0.7.6\n",
"version_information 1.0.3\n",
"Sat Aug 15 10:38:48 2015 JST"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%load_ext version_information\n",
"\n",
"%version_information numpy, scipy, matplotlib, sympy, version_information"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
#
# Build a PDF with all the notebooks
#
TEMPLATE=chapter
NOTEBOOKS=Lecture-0-Scientific-Computing-with-Python.ipynb \
Lecture-1-Introduction-to-Python-Programming.ipynb \
Lecture-2-Numpy.ipynb Lecture-3-Scipy.ipynb \
Lecture-4-Matplotlib.ipynb Lecture-5-Sympy.ipynb \
Lecture-6A-Fortran-and-C.ipynb Lecture-6B-HPC.ipynb \
Lecture-7-Revision-Control-Software.ipynb
LATEXFILES=$(NOTEBOOKS:.ipynb=.tex)
.ipynb.tex:
jupyter nbconvert --to latex --template $(TEMPLATE) $<
all: latexfiles buildpdf
latexfiles:
for notebook in $(NOTEBOOKS) ; do \
jupyter nbconvert --to latex --template $(TEMPLATE) $$notebook ; \
done
buildpdf: latexfiles
pdflatex Scientific-Computing-with-Python.tex

View File

@@ -0,0 +1,40 @@
Lectures on scientific computing with Python
============================================
<a href="https://notebooks.azure.com/import/gh/jrjohansson/scientific-python-lectures"><img src="https://notebooks.azure.com/launch.png" /></a>
A set of lectures on scientific computing with Python, using IPython notebooks.
To open these notebooks in IPython, download the files to a directory on your computer and from that directory run:
$ ipython notebook
This will open a new page in your browser with a list of the available notebooks.
Should this error `[TerminalIPythonApp] WARNING | File not found: u'notebook'` pop up, please install Jupyter by following the [instructions](http://jupyter.readthedocs.io/en/latest/install.html) and execute the following command to run the notebook:
$ jupyter notebook
Online read-only versions
=========================
Use the following links:
* [Lecture-0 Scientific Computing with Python](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-0-Scientific-Computing-with-Python.ipynb)
* [Lecture-1 Introduction to Python Programming](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-1-Introduction-to-Python-Programming.ipynb)
* [Lecture-2 Numpy - multidimensional data arrays](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-2-Numpy.ipynb)
* [Lecture-3 Scipy - Library of scientific algorithms](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-3-Scipy.ipynb)
* [Lecture-4 Matplotlib - 2D and 3D plotting](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-4-Matplotlib.ipynb)
* [Lecture-5 Sympy - Symbolic algebra](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-5-Sympy.ipynb)
* [Lecture-6A C and Fortran integration](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-6A-Fortran-and-C.ipynb)
* [Lecture-6B HPC](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-6B-HPC.ipynb)
* [Lecture-7 Revision Control Software](http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-7-Revision-Control-Software.ipynb)
A PDF file containing all the lectures is available here: [Scientific Computing with Python](http://raw.github.com/jrjohansson/scientific-python-lectures/master/Scientific-Computing-with-Python.pdf)
License
=======
This work is licensed under a [Creative Commons Attribution 3.0 Unported License.](http://creativecommons.org/licenses/by/3.0/)

View File

@@ -0,0 +1,260 @@
\documentclass{report}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}}
\usepackage{caption}
\DeclareCaptionLabelFormat{nolabel}{}
\captionsetup{labelformat=nolabel}
\usepackage{adjustbox} % Used to constrain images to a maximum size
\usepackage{xcolor} % Allow colors to be defined
\usepackage{enumerate} % Needed for markdown enumerations to work
\usepackage{geometry} % Used to adjust the document margins
\usepackage{amsmath} % Equations
\usepackage{amssymb} % Equations
\usepackage{textcomp} % defines textquotesingle
\AtBeginDocument{%
\def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code
}
\usepackage{upquote} % Upright quotes for verbatim code
\usepackage{eurosym} % defines \euro
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
\usepackage{fancyvrb} % verbatim replacement that allows latex
\usepackage{grffile} % extends the file name processing of package graphics
\usepackage{hyperref}
\usepackage{longtable} % longtable support required by pandoc >1.10
\usepackage{booktabs} % table support for pandoc > 1.12.2
\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout)
% Colors for the hyperref package
\definecolor{urlcolor}{rgb}{0,.145,.698}
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
\definecolor{citecolor}{rgb}{.12,.54,.11}
% ANSI colors
\definecolor{ansi-black}{HTML}{3E424D}
\definecolor{ansi-black-intense}{HTML}{282C36}
\definecolor{ansi-red}{HTML}{E75C58}
\definecolor{ansi-red-intense}{HTML}{B22B31}
\definecolor{ansi-green}{HTML}{00A250}
\definecolor{ansi-green-intense}{HTML}{007427}
\definecolor{ansi-yellow}{HTML}{DDB62B}
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
\definecolor{ansi-blue}{HTML}{208FFB}
\definecolor{ansi-blue-intense}{HTML}{0065CA}
\definecolor{ansi-magenta}{HTML}{D160C4}
\definecolor{ansi-magenta-intense}{HTML}{A03196}
\definecolor{ansi-cyan}{HTML}{60C6C8}
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
\definecolor{ansi-white}{HTML}{C5C1B4}
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
% commands and environments needed by pandoc snippets
% extracted from the output of `pandoc -s`
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
% Additional commands for more recent versions of Pandoc
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
% Define a nice break command that doesn't care if a line doesn't already
% exist.
\def\br{\hspace*{\fill} \\* }
% Math Jax compatability definitions
\def\gt{>}
\def\lt{<}
% Pygments definitions
\makeatletter
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
\let\PY@ul=\relax \let\PY@tc=\relax%
\let\PY@bc=\relax \let\PY@ff=\relax}
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
\def\PY@toks#1+{\ifx\relax#1\empty\else%
\PY@tok{#1}\expandafter\PY@toks\fi}
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
\expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf}
\expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit}
\expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
\expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
\expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
\expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
\expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
\expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
\expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
\expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
\expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\def\PYZbs{\char`\\}
\def\PYZus{\char`\_}
\def\PYZob{\char`\{}
\def\PYZcb{\char`\}}
\def\PYZca{\char`\^}
\def\PYZam{\char`\&}
\def\PYZlt{\char`\<}
\def\PYZgt{\char`\>}
\def\PYZsh{\char`\#}
\def\PYZpc{\char`\%}
\def\PYZdl{\char`\$}
\def\PYZhy{\char`\-}
\def\PYZsq{\char`\'}
\def\PYZdq{\char`\"}
\def\PYZti{\char`\~}
% for compatibility with earlier versions
\def\PYZat{@}
\def\PYZlb{[}
\def\PYZrb{]}
\makeatother
% Exact colors from NB
\definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
\hypersetup{
breaklinks=true, % so long urls are correctly broken across lines
colorlinks=true,
urlcolor=urlcolor,
linkcolor=linkcolor,
citecolor=citecolor,
}
% Slightly bigger margins than the latex defaults
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\title{Introduction to Scientific Computing in Python}
\author{Robert Johansson}
\begin{document}
\maketitle
\tableofcontents
\newpage
\input{Lecture-0-Scientific-Computing-with-Python}
\newpage
\input{Lecture-1-Introduction-to-Python-Programming}
\newpage
\input{Lecture-2-Numpy}
\newpage
\input{Lecture-3-Scipy}
\newpage
\input{Lecture-4-Matplotlib}
\newpage
\input{Lecture-5-Sympy}
\newpage
\input{Lecture-6A-Fortran-and-C}
\newpage
\input{Lecture-6B-HPC}
\newpage
\input{Lecture-7-Revision-Control-Software}
\end{document}

View File

@@ -0,0 +1,120 @@
((*- extends 'display_priority.tplx' -*))
%===============================================================================
% Abstract overrides
%===============================================================================
((* block header *))
((* endblock header *))
((* block body *))
((( super() )))
((* endblock body *))
%===============================================================================
% Support blocks
%===============================================================================
% Displaying simple data text
((* block data_text *))
\begin{verbatim}
((( output.data['text/plain'] )))
\end{verbatim}
((* endblock data_text *))
% Display python error text as-is
((* block error *))
\begin{Verbatim}[commandchars=\\\{\}]
((( super() )))
\end{Verbatim}
((* endblock error *))
((* block traceback_line *))
((( line | indent | strip_ansi | escape_latex )))
((* endblock traceback_line *))
% Display stream ouput with coloring
((* block stream *))
\begin{Verbatim}[commandchars=\\\{\}]
((( output.text | escape_latex | ansi2latex )))
\end{Verbatim}
((* endblock stream *))
% Display latex
((* block data_latex -*))
((( output.data['text/latex'] | citation2latex | strip_files_prefix | markdown2latex )))
((* endblock data_latex *))
% Display markdown
((* block data_markdown -*))
((( output.data['text/markdown'] | citation2latex | strip_files_prefix | markdown2latex )))
((* endblock data_markdown *))
% Default mechanism for rendering figures
((*- block data_png -*))((( draw_figure(output.metadata.filenames['image/png']) )))((*- endblock -*))
((*- block data_jpg -*))((( draw_figure(output.metadata.filenames['image/jpeg']) )))((*- endblock -*))
((*- block data_svg -*))((( draw_figure(output.metadata.filenames['image/svg+xml']) )))((*- endblock -*))
((*- block data_pdf -*))((( draw_figure(output.metadata.filenames['application/pdf']) )))((*- endblock -*))
% Draw a figure using the graphicx package.
((* macro draw_figure(filename) -*))
((* set filename = filename | posix_path *))
((*- block figure scoped -*))
\begin{center}
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{((( filename )))}
\end{center}
{ \hspace*{\fill} \\}
((*- endblock figure -*))
((*- endmacro *))
% Render markdown
((* block markdowncell scoped *))
((( cell.source | citation2latex | strip_files_prefix | markdown2latex(extra_args=["--chapters"]) )))
((* endblock markdowncell *))
% Don't display unknown types
((* block unknowncell scoped *))
((* endblock unknowncell *))
%===============================================================================
% Input
%===============================================================================
((* block input scoped *))
((( add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor') )))
((* endblock input *))
%===============================================================================
% Output
%===============================================================================
((* block execute_result scoped *))
((*- for type in output.data | filter_data_type -*))
((*- if type in ['text/plain']*))
((( add_prompt(output.data['text/plain'] | escape_latex, cell, 'Out', 'outcolor') )))
((* else -*))
\texttt{\color{outcolor}Out[{\color{outcolor}((( cell.execution_count )))}]:}((( super() )))
((*- endif -*))
((*- endfor -*))
((* endblock execute_result *))
%==============================================================================
% Support Macros
%==============================================================================
% Name: draw_prompt
% Purpose: Renders an output/input prompt
((* macro add_prompt(text, cell, prompt, prompt_color) -*))
((*- if cell.execution_count is defined -*))
((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
((*- else -*))
((*- set execution_count = " " -*))
((*- endif -*))
((*- set indention = " " * (execution_count | length + 7) -*))
\begin{Verbatim}[commandchars=\\\{\}]
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@@ -0,0 +1,307 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="130.75"
height="145.75002"
id="svg2"
version="1.1"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="scientific-python-stack.svg"
inkscape:export-filename="scientific-python-stack.png"
inkscape:export-xdpi="344.17001"
inkscape:export-ydpi="344.17001">
<defs
id="defs4">
<path
sodipodi:end="2.6179939"
sodipodi:start="0.55850536"
d="m 317.89812,194.20932 a 79.64286,79.64286 0 0 1 -136.51371,-2.38286 l 68.97274,-39.82142 z"
sodipodi:ry="79.64286"
sodipodi:rx="79.64286"
sodipodi:cy="152.00504"
sodipodi:cx="250.35715"
id="path3779-9-1-34-2"
style="fill:#e6e6e6;fill-opacity:1;stroke:#666666;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
sodipodi:type="arc"
transform="matrix(-1,0,0,1,423.66072,164.10715)" />
<path
style="fill:none;stroke:none"
d="m 121.78572,347.71932 c 27.47833,37.9228 73.84073,35.52916 108.21428,3.21429"
id="path4417-4"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 175.71429,252.36218 c 45.17969,12.19595 56.69027,45.75883 52.5,89.28571"
id="path4415-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 123.21428,340.21932 c -9.44058,-51.7873 13.51269,-77.59604 47.14286,-88.21428"
id="path4375-0"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.959798"
inkscape:cx="38.576964"
inkscape:cy="52.333249"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:snap-global="true"
inkscape:window-width="1791"
inkscape:window-height="1027"
inkscape:window-x="127"
inkscape:window-y="24"
inkscape:window-maximized="0"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0">
<inkscape:grid
type="xygrid"
id="grid2985"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
originx="-299.625px"
originy="-794.62499px" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-299.625,-111.98717)">
<flowRoot
xml:space="preserve"
id="flowRoot4680"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"><flowRegion
id="flowRegion4682"><rect
id="rect4684"
width="296.42856"
height="350"
x="-3.5714285"
y="125.21932" /></flowRegion><flowPara
id="flowPara4686" /></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot4688"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"><flowRegion
id="flowRegion4690"><rect
id="rect4692"
width="271.42856"
height="291.42856"
x="60.714287"
y="168.07646" /></flowRegion><flowPara
id="flowPara4694" /></flowRoot> <rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210"
width="40"
height="25"
x="345"
y="172.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-4"
width="40"
height="25"
x="390"
y="172.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-4-8"
width="85"
height="25"
x="345"
y="202.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-3"
width="40"
height="54.999992"
x="300"
y="172.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-4-8-7"
width="130"
height="25"
x="300"
y="232.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-4-8-7-7"
width="130"
height="25"
x="300"
y="142.36218"
rx="2" />
<rect
style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.75;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3210-4-8-7-7-3"
width="130"
height="25"
x="300"
y="112.36217"
rx="2" />
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="364.99414"
y="243.57697"
id="text4544-9-8"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8"
x="364.99414"
y="243.57697"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Python</tspan><tspan
sodipodi:role="line"
x="364.99414"
y="251.6396"
id="tspan4552-8-0"
style="font-size:6px;text-align:center;text-anchor:middle">Lecture 1</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="387.46289"
y="213.42072"
id="text4544-9-8-5"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8-9"
x="387.46289"
y="213.42072"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Numpy</tspan><tspan
sodipodi:role="line"
x="387.46289"
y="221.48335"
id="tspan4552-8-0-5"
style="font-size:6px;text-align:center;text-anchor:middle">Lecture 2</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="365.03076"
y="183.57697"
id="text4544-9-8-5-0-9"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8-9-7-5"
x="365.03076"
y="183.57697"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Scipy</tspan><tspan
sodipodi:role="line"
x="365.03076"
y="191.6396"
id="tspan4552-8-0-5-6-1"
style="font-size:6px;text-align:center;text-anchor:middle">Lecture 3</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="410.05664"
y="183.57697"
id="text4544-9-8-5-0"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8-9-7"
x="410.05664"
y="183.57697"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">matplotlib</tspan><tspan
sodipodi:role="line"
x="410.05664"
y="191.6396"
id="tspan4552-8-0-5-6"
style="font-size:6px;text-align:center;text-anchor:middle">Lecture 4</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="319.82617"
y="198.45"
id="text4544-9-8-5-0-9-7"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8-9-7-5-9"
x="319.82617"
y="198.45"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Sympy</tspan><tspan
sodipodi:role="line"
x="319.82617"
y="206.51263"
id="tspan4552-8-0-5-6-1-6"
style="font-size:6px;text-align:center;text-anchor:middle">Lecture 5</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="364.90039"
y="152.9588"
id="text4544-9-8-9"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-8-91"
x="364.90039"
y="152.9588"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Other packages and toolboxes</tspan><tspan
sodipodi:role="line"
x="364.90039"
y="161.02144"
id="tspan4552-8-0-2"
style="font-size:6px;text-align:center;text-anchor:middle">for example QuTiP</tspan></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="364.99609"
y="126.5985"
id="text4544-9-8-9-0"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
x="364.99609"
y="126.5985"
id="tspan4552-8-0-2-0"
style="font-size:8px;font-weight:bold;text-align:center;text-anchor:middle;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">User programs</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot3370"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
transform="translate(447.52906,234.62469)"><flowRegion
id="flowRegion3372"><rect
id="rect3374"
width="277.79196"
height="474.7717"
x="-11.111678"
y="-223.85219" /></flowRegion><flowPara
id="flowPara3376" /></flowRoot> </g>
</svg>

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@@ -0,0 +1,292 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="164.94188"
height="164.04639"
id="svg2"
version="1.1"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="theory-experiment-computation.pdf"
inkscape:export-filename="theory-experiment-computation.png"
inkscape:export-xdpi="436.48999"
inkscape:export-ydpi="436.48999">
<defs
id="defs4">
<path
sodipodi:end="2.6179939"
sodipodi:start="0.55850536"
d="m 317.89812,194.20932 a 79.64286,79.64286 0 0 1 -136.51371,-2.38286 l 68.97274,-39.82142 z"
sodipodi:ry="79.64286"
sodipodi:rx="79.64286"
sodipodi:cy="152.00504"
sodipodi:cx="250.35715"
id="path3779-9-1-34-2"
style="fill:#e6e6e6;fill-opacity:1;stroke:#666666;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
sodipodi:type="arc"
transform="matrix(-1,0,0,1,423.66072,164.10715)" />
<path
style="fill:none;stroke:none"
d="m 121.78572,347.71932 c 27.47833,37.9228 73.84073,35.52916 108.21428,3.21429"
id="path4417-4"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 175.71429,252.36218 c 45.17969,12.19595 56.69027,45.75883 52.5,89.28571"
id="path4415-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 123.21428,340.21932 c -9.44058,-51.7873 13.51269,-77.59604 47.14286,-88.21428"
id="path4375-0"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="-137.18251"
inkscape:cy="97.52171"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:snap-global="false"
inkscape:window-width="1791"
inkscape:window-height="1200"
inkscape:window-x="419"
inkscape:window-y="141"
inkscape:window-maximized="0"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0">
<inkscape:grid
type="xygrid"
id="grid2985"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
originx="-447.52906px"
originy="-653.6911px" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-447.52906,-234.62469)">
<path
transform="matrix(-1,0,0,1,780.26121,166.51252)"
sodipodi:type="arc"
style="fill:#e6e6e6;fill-opacity:1;stroke:#666666;stroke-width:1;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path3779-9-1-34-5"
sodipodi:cx="250.35715"
sodipodi:cy="152.00504"
sodipodi:rx="79.64286"
sodipodi:ry="79.64286"
d="m 317.89812,194.20932 c -23.30878,37.30185 -72.44341,48.64548 -109.74526,25.33669 -11.05732,-6.90938 -20.24918,-16.42783 -26.76845,-27.71955 l 68.97274,-39.82142 z"
sodipodi:start="0.55850536"
sodipodi:end="2.6179939" />
<path
transform="matrix(-1,0,0,1,782.67193,162.76252)"
sodipodi:type="arc"
style="fill:#e6e6e6;fill-opacity:1;stroke:#666666;stroke-width:1;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path3779-9-1-8-5-4"
sodipodi:cx="250.35715"
sodipodi:cy="152.00504"
sodipodi:rx="79.64286"
sodipodi:ry="79.64286"
d="m 181.38441,191.82646 c -21.99277,-38.09259 -8.94128,-86.8014 29.15131,-108.794166 12.10724,-6.990121 25.84119,-10.670119 39.82143,-10.670119 l 0,79.642865 z"
sodipodi:start="2.6179939"
sodipodi:end="4.712389" />
<path
transform="matrix(-1,0,0,1,778.02907,162.76252)"
sodipodi:type="arc"
style="fill:#e6e6e6;fill-opacity:1;stroke:#666666;stroke-width:1;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path3779-9-1-8-3-3-0"
sodipodi:cx="250.35715"
sodipodi:cy="152.00504"
sodipodi:rx="79.64286"
sodipodi:ry="79.64286"
d="m 250.35715,72.362175 c 43.98554,1e-6 79.64286,35.657325 79.64286,79.642865 0,14.9241 -4.19332,29.54793 -12.10189,42.20428 l -67.54097,-42.20428 z"
sodipodi:start="4.712389"
sodipodi:end="6.8416907" />
<path
style="fill:none;stroke:none"
d="m 479.81477,342.62469 c -9.44058,-51.7873 13.51269,-77.59604 47.14286,-88.21428"
id="path4495"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 532.31478,254.76755 c 45.17969,12.19595 56.69027,45.75883 52.5,89.28571"
id="path4499"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:none"
d="m 478.38621,350.12469 c 27.47833,37.9228 73.84073,35.52916 108.21428,3.21429"
id="path4501"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="531.23541"
y="353.33661"
id="text4544"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546"
x="531.23541"
y="353.33661"
style="font-size:11px;font-weight:bold;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Experiment</tspan><tspan
sodipodi:role="line"
x="531.23541"
y="364.18057"
id="tspan4548"
style="font-size:8px;text-align:center;text-anchor:middle">measurements, observations,</tspan><tspan
sodipodi:role="line"
x="531.23541"
y="374.18057"
id="tspan4562"
style="font-size:8px;text-align:center;text-anchor:middle">collect data, test hypothesis,</tspan><tspan
sodipodi:role="line"
x="531.23541"
y="384.18057"
style="font-size:10px;text-align:center;text-anchor:middle"
id="tspan4613"><tspan
style="font-size:8px"
id="tspan4615">...</tspan></tspan><tspan
sodipodi:role="line"
x="531.23541"
y="394.18057"
id="tspan4552" /></text>
<text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="466.14908"
y="276.60513"
id="text4544-9"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5"
x="466.14908"
y="276.60513"
style="font-size:11px;font-weight:bold;text-align:start;text-anchor:start;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Theory</tspan><tspan
sodipodi:role="line"
x="466.14908"
y="287.4491"
id="tspan4562-0"
style="font-size:8px;text-align:start;text-anchor:start"> develop models,</tspan><tspan
sodipodi:role="line"
x="466.14908"
y="297.4491"
style="font-size:8px;text-align:start;text-anchor:start"
id="tspan4605"> hypothesis,</tspan><tspan
sodipodi:role="line"
x="466.14908"
y="307.4491"
style="font-size:8px;text-align:start;text-anchor:start"
id="tspan4607"> predictions, </tspan><tspan
sodipodi:role="line"
x="466.14908"
y="317.4491"
style="font-size:8px;text-align:start;text-anchor:start"
id="tspan4611"> conclusions,</tspan><tspan
sodipodi:role="line"
x="466.14908"
y="327.4491"
style="font-size:8px;text-align:start;text-anchor:start"
id="tspan4676"> ...</tspan><tspan
sodipodi:role="line"
x="466.14908"
y="337.4491"
id="tspan4552-8"
style="font-size:8px" /></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"
x="535.32928"
y="276.60513"
id="text4544-9-5"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan4546-5-7"
x="535.32928"
y="276.60513"
style="font-size:11px;font-weight:bold;text-align:start;text-anchor:start;fill:#0066ff;-inkscape-font-specification:Liberation Serif Bold">Computation</tspan><tspan
sodipodi:role="line"
x="535.32928"
y="287.4491"
style="font-size:8px;text-align:start;text-anchor:start;fill:#1c2422"
id="tspan4660"> simulate models,</tspan><tspan
sodipodi:role="line"
x="535.32928"
y="297.4491"
style="font-size:8px;text-align:start;text-anchor:start;fill:#1c2422"
id="tspan4662"> test hypothesis,</tspan><tspan
sodipodi:role="line"
x="535.32928"
y="307.4491"
id="tspan4552-8-6"
style="font-size:8px;text-align:start;text-anchor:start;fill:#1c2422"> observations,</tspan><tspan
sodipodi:role="line"
x="535.32928"
y="317.4491"
style="font-size:8px;text-align:start;text-anchor:start;fill:#1c2422"
id="tspan4674"> visualizations, </tspan><tspan
sodipodi:role="line"
x="535.32928"
y="327.4491"
style="font-size:8px;text-align:start;text-anchor:start;fill:#1c2422"
id="tspan4678"> ...</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot4680"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"><flowRegion
id="flowRegion4682"><rect
id="rect4684"
width="296.42856"
height="350"
x="-3.5714285"
y="125.21932" /></flowRegion><flowPara
id="flowPara4686"></flowPara></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot4688"
style="font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Liberation Serif;-inkscape-font-specification:Liberation Serif"><flowRegion
id="flowRegion4690"><rect
id="rect4692"
width="271.42856"
height="291.42856"
x="60.714287"
y="168.07646" /></flowRegion><flowPara
id="flowPara4694"></flowPara></flowRoot> </g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print("Hej världen!")

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env python
print("Hello world!")

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
# year hare lynx carrot
1900 30e3 4e3 48300
1901 47.2e3 6.1e3 48200
1902 70.2e3 9.8e3 41500
1903 77.4e3 35.2e3 38200
1904 36.3e3 59.4e3 40600
1905 20.6e3 41.7e3 39800
1906 18.1e3 19e3 38600
1907 21.4e3 13e3 42300
1908 22e3 8.3e3 44500
1909 25.4e3 9.1e3 42100
1910 27.1e3 7.4e3 46000
1911 40.3e3 8e3 46800
1912 57e3 12.3e3 43800
1913 76.6e3 19.5e3 40900
1914 52.3e3 45.7e3 39400
1915 19.5e3 51.1e3 39000
1916 11.2e3 29.7e3 36700
1917 7.6e3 15.8e3 41800
1918 14.6e3 9.7e3 43300
1919 16.2e3 10.1e3 41300
1920 24.7e3 8.6e3 47300

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 1\n\nSolution of the exercise 1 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nn = 256\nX = np.linspace(-np.pi, np.pi, 256)\nC, S = np.cos(X), np.sin(X)\nplt.plot(X, C)\nplt.plot(X, S)\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise\n\nExercises with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nC, S = np.cos(X), np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\", label=\"cosine\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\", label=\"sine\")\n\nax = plt.gca()\nax.spines[\"right\"].set_color(\"none\")\nax.spines[\"top\"].set_color(\"none\")\nax.xaxis.set_ticks_position(\"bottom\")\nax.spines[\"bottom\"].set_position((\"data\", 0))\nax.yaxis.set_ticks_position(\"left\")\nax.spines[\"left\"].set_position((\"data\", 0))\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks(\n [-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],\n [r\"$-\\pi$\", r\"$-\\pi/2$\", r\"$0$\", r\"$+\\pi/2$\", r\"$+\\pi$\"],\n)\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, 1], [r\"$-1$\", r\"$+1$\"])\n\nplt.legend(loc=\"upper left\")\n\nt = 2 * np.pi / 3\nplt.plot([t, t], [0, np.cos(t)], color=\"blue\", linewidth=1.5, linestyle=\"--\")\nplt.scatter(\n [\n t,\n ],\n [\n np.cos(t),\n ],\n 50,\n color=\"blue\",\n)\nplt.annotate(\n r\"$sin(\\frac{2\\pi}{3})=\\frac{\\sqrt{3}}{2}$\",\n xy=(t, np.sin(t)),\n xycoords=\"data\",\n xytext=(10, 30),\n textcoords=\"offset points\",\n fontsize=16,\n arrowprops={\"arrowstyle\": \"->\", \"connectionstyle\": \"arc3,rad=.2\"},\n)\n\nplt.plot([t, t], [0, np.sin(t)], color=\"red\", linewidth=1.5, linestyle=\"--\")\nplt.scatter(\n [\n t,\n ],\n [\n np.sin(t),\n ],\n 50,\n color=\"red\",\n)\nplt.annotate(\n r\"$cos(\\frac{2\\pi}{3})=-\\frac{1}{2}$\",\n xy=(t, np.cos(t)),\n xycoords=\"data\",\n xytext=(-90, -50),\n textcoords=\"offset points\",\n fontsize=16,\n arrowprops={\"arrowstyle\": \"->\", \"connectionstyle\": \"arc3,rad=.2\"},\n)\n\nfor label in ax.get_xticklabels() + ax.get_yticklabels():\n label.set_fontsize(16)\n label.set_bbox({\"facecolor\": \"white\", \"edgecolor\": \"None\", \"alpha\": 0.65})\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 2\n\nExercise 2 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n# Create a new figure of size 8x6 points, using 100 dots per inch\nplt.figure(figsize=(8, 6), dpi=80)\n\n# Create a new subplot from a grid of 1x1\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nC, S = np.cos(X), np.sin(X)\n\n# Plot cosine using blue color with a continuous line of width 1 (pixels)\nplt.plot(X, C, color=\"blue\", linewidth=1.0, linestyle=\"-\")\n\n# Plot sine using green color with a continuous line of width 1 (pixels)\nplt.plot(X, S, color=\"green\", linewidth=1.0, linestyle=\"-\")\n\n# Set x limits\nplt.xlim(-4.0, 4.0)\n\n# Set x ticks\nplt.xticks(np.linspace(-4, 4, 9))\n\n# Set y limits\nplt.ylim(-1.0, 1.0)\n\n# Set y ticks\nplt.yticks(np.linspace(-1, 1, 5))\n\n# Show result on screen\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 3\n\nExercise 3 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nC, S = np.cos(X), np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\")\n\nplt.xlim(-4.0, 4.0)\nplt.xticks(np.linspace(-4, 4, 9))\n\nplt.ylim(-1.0, 1.0)\nplt.yticks(np.linspace(-1, 1, 5))\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 4\n\nExercise 4 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nS = np.sin(X)\nC = np.cos(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\")\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 5\n\nExercise 5 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nS = np.sin(X)\nC = np.cos(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\")\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi])\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, 0, +1])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 6\n\nExercise 6 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256)\nC = np.cos(X)\nS = np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\")\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks(\n [-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],\n [r\"$-\\pi$\", r\"$-\\pi/2$\", r\"$0$\", r\"$+\\pi/2$\", r\"$+\\pi$\"],\n)\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, 0, +1], [r\"$-1$\", r\"$0$\", r\"$+1$\"])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 7\n\nExercise 7 with matplotlib\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256, endpoint=True)\nC = np.cos(X)\nS = np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\")\n\nax = plt.gca()\nax.spines[\"right\"].set_color(\"none\")\nax.spines[\"top\"].set_color(\"none\")\nax.xaxis.set_ticks_position(\"bottom\")\nax.spines[\"bottom\"].set_position((\"data\", 0))\nax.yaxis.set_ticks_position(\"left\")\nax.spines[\"left\"].set_position((\"data\", 0))\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks(\n [-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],\n [r\"$-\\pi$\", r\"$-\\pi/2$\", r\"$0$\", r\"$+\\pi/2$\", r\"$+\\pi$\"],\n)\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, 0, +1], [r\"$-1$\", r\"$0$\", r\"$+1$\"])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 8\n\nExercise 8 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256, endpoint=True)\nC = np.cos(X)\nS = np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\", label=\"cosine\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\", label=\"sine\")\n\nax = plt.gca()\nax.spines[\"right\"].set_color(\"none\")\nax.spines[\"top\"].set_color(\"none\")\nax.xaxis.set_ticks_position(\"bottom\")\nax.spines[\"bottom\"].set_position((\"data\", 0))\nax.yaxis.set_ticks_position(\"left\")\nax.spines[\"left\"].set_position((\"data\", 0))\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks(\n [-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],\n [r\"$-\\pi$\", r\"$-\\pi/2$\", r\"$0$\", r\"$+\\pi/2$\", r\"$+\\pi$\"],\n)\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, +1], [r\"$-1$\", r\"$+1$\"])\n\nplt.legend(loc=\"upper left\")\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Exercise 9\n\nExercise 9 with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(8, 5), dpi=80)\nplt.subplot(111)\n\nX = np.linspace(-np.pi, np.pi, 256, endpoint=True)\nC = np.cos(X)\nS = np.sin(X)\n\nplt.plot(X, C, color=\"blue\", linewidth=2.5, linestyle=\"-\", label=\"cosine\")\nplt.plot(X, S, color=\"red\", linewidth=2.5, linestyle=\"-\", label=\"sine\")\n\nax = plt.gca()\nax.spines[\"right\"].set_color(\"none\")\nax.spines[\"top\"].set_color(\"none\")\nax.xaxis.set_ticks_position(\"bottom\")\nax.spines[\"bottom\"].set_position((\"data\", 0))\nax.yaxis.set_ticks_position(\"left\")\nax.spines[\"left\"].set_position((\"data\", 0))\n\nplt.xlim(X.min() * 1.1, X.max() * 1.1)\nplt.xticks(\n [-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],\n [r\"$-\\pi$\", r\"$-\\pi/2$\", r\"$0$\", r\"$+\\pi/2$\", r\"$+\\pi$\"],\n)\n\nplt.ylim(C.min() * 1.1, C.max() * 1.1)\nplt.yticks([-1, +1], [r\"$-1$\", r\"$+1$\"])\n\nt = 2 * np.pi / 3\nplt.plot([t, t], [0, np.cos(t)], color=\"blue\", linewidth=1.5, linestyle=\"--\")\nplt.scatter(\n [\n t,\n ],\n [\n np.cos(t),\n ],\n 50,\n color=\"blue\",\n)\nplt.annotate(\n r\"$sin(\\frac{2\\pi}{3})=\\frac{\\sqrt{3}}{2}$\",\n xy=(t, np.sin(t)),\n xycoords=\"data\",\n xytext=(+10, +30),\n textcoords=\"offset points\",\n fontsize=16,\n arrowprops={\"arrowstyle\": \"->\", \"connectionstyle\": \"arc3,rad=.2\"},\n)\n\nplt.plot([t, t], [0, np.sin(t)], color=\"red\", linewidth=1.5, linestyle=\"--\")\nplt.scatter(\n [\n t,\n ],\n [\n np.sin(t),\n ],\n 50,\n color=\"red\",\n)\nplt.annotate(\n r\"$cos(\\frac{2\\pi}{3})=-\\frac{1}{2}$\",\n xy=(t, np.cos(t)),\n xycoords=\"data\",\n xytext=(-90, -50),\n textcoords=\"offset points\",\n fontsize=16,\n arrowprops={\"arrowstyle\": \"->\", \"connectionstyle\": \"arc3,rad=.2\"},\n)\n\nplt.legend(loc=\"upper left\")\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Aliased versus anti-aliased\n\nThis example demonstrates aliased versus anti-aliased text.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 128, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\n\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.rcParams[\"text.antialiased\"] = False\nplt.text(0.5, 0.5, \"Aliased\", ha=\"center\", va=\"center\")\n\nplt.xlim(0, 1)\nplt.ylim(0, 1)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Alpha: transparency\n\nThis example demonstrates using alpha for transparency.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0.1, 1, 0.8), frameon=False)\n\nfor i in range(1, 11):\n plt.axvline(i, linewidth=1, color=\"blue\", alpha=0.25 + 0.75 * i / 10.0)\n\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Aliased versus anti-aliased\n\nThe example shows aliased versus anti-aliased text.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 128, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.rcParams[\"text.antialiased\"] = True\nplt.text(0.5, 0.5, \"Anti-aliased\", ha=\"center\", va=\"center\")\n\nplt.xlim(0, 1)\nplt.ylim(0, 1)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# The colors matplotlib line plots\n\nAn example demoing the various colors taken by matplotlib's plot.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0.1, 1, 0.8), frameon=False)\n\nfor i in range(1, 11):\n plt.plot([i, i], [0, 1], lw=1.5)\n\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Colormaps\n\nAn example plotting the matplotlib colormaps.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n\nimport matplotlib\nimport matplotlib.pyplot as plt\n\n\nplt.rc(\"text\", usetex=False)\na = np.outer(np.arange(0, 1, 0.01), np.ones(10))\n\nplt.figure(figsize=(10, 5))\nplt.subplots_adjust(top=0.8, bottom=0.05, left=0.01, right=0.99)\nmaps = [m for m in matplotlib.colormaps if not m.endswith(\"_r\")]\nmaps.sort()\nl = len(maps) + 1\n\nfor i, m in enumerate(maps):\n plt.subplot(1, l, i + 1)\n plt.axis(\"off\")\n plt.imshow(a, aspect=\"auto\", cmap=plt.get_cmap(m), origin=\"lower\")\n plt.title(m, rotation=90, fontsize=10, va=\"bottom\")\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Dash capstyle\n\nAn example demoing the dash capstyle.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.plot(\n np.arange(4),\n np.ones(4),\n color=\"blue\",\n dashes=[15, 15],\n linewidth=8,\n dash_capstyle=\"butt\",\n)\n\nplt.plot(\n 5 + np.arange(4),\n np.ones(4),\n color=\"blue\",\n dashes=[15, 15],\n linewidth=8,\n dash_capstyle=\"round\",\n)\n\nplt.plot(\n 10 + np.arange(4),\n np.ones(4),\n color=\"blue\",\n dashes=[15, 15],\n linewidth=8,\n dash_capstyle=\"projecting\",\n)\n\nplt.xlim(0, 14)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Dash join style\n\nExample demoing the dash join style.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.plot(\n np.arange(3),\n [0, 1, 0],\n color=\"blue\",\n dashes=[12, 5],\n linewidth=8,\n dash_joinstyle=\"miter\",\n)\nplt.plot(\n 4 + np.arange(3),\n [0, 1, 0],\n color=\"blue\",\n dashes=[12, 5],\n linewidth=8,\n dash_joinstyle=\"bevel\",\n)\nplt.plot(\n 8 + np.arange(3),\n [0, 1, 0],\n color=\"blue\",\n dashes=[12, 5],\n linewidth=8,\n dash_joinstyle=\"round\",\n)\n\nplt.xlim(0, 12)\nplt.ylim(-1, 2)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Linestyles\n\nPlot the different line styles.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n\ndef linestyle(ls, i):\n X = i * 0.5 * np.ones(11)\n Y = np.arange(11)\n plt.plot(\n X,\n Y,\n ls,\n color=(0.0, 0.0, 1, 1),\n lw=3,\n ms=8,\n mfc=(0.75, 0.75, 1, 1),\n mec=(0, 0, 1, 1),\n )\n plt.text(0.5 * i, 10.25, ls, rotation=90, fontsize=15, va=\"bottom\")\n\n\nlinestyles = [\n \"-\",\n \"--\",\n \":\",\n \"-.\",\n \".\",\n \",\",\n \"o\",\n \"^\",\n \"v\",\n \"<\",\n \">\",\n \"s\",\n \"+\",\n \"x\",\n \"d\",\n \"1\",\n \"2\",\n \"3\",\n \"4\",\n \"h\",\n \"p\",\n \"|\",\n \"_\",\n \"D\",\n \"H\",\n]\nn_lines = len(linestyles)\n\nsize = 20 * n_lines, 300\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nplt.axes((0, 0.01, 1, 0.9), frameon=False)\n\nfor i, ls in enumerate(linestyles):\n linestyle(ls, i)\n\nplt.xlim(-0.2, 0.2 + 0.5 * n_lines)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Linewidth\n\nPlot various linewidth with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0.1, 1, 0.8), frameon=False)\n\nfor i in range(1, 11):\n plt.plot([i, i], [0, 1], color=\"b\", lw=i / 2.0)\n\nplt.xlim(0, 11)\nplt.ylim(0, 1)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Markers\n\nShow the different markers of matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n\ndef marker(m, i):\n X = i * 0.5 * np.ones(11)\n Y = np.arange(11)\n\n plt.plot(X, Y, lw=1, marker=m, ms=10, mfc=(0.75, 0.75, 1, 1), mec=(0, 0, 1, 1))\n plt.text(0.5 * i, 10.25, repr(m), rotation=90, fontsize=15, va=\"bottom\")\n\n\nmarkers = [\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n \"o\",\n \"h\",\n \"_\",\n \"1\",\n \"2\",\n \"3\",\n \"4\",\n \"8\",\n \"p\",\n \"^\",\n \"v\",\n \"<\",\n \">\",\n \"|\",\n \"d\",\n \",\",\n \"+\",\n \"s\",\n \"*\",\n \"|\",\n \"x\",\n \"D\",\n \"H\",\n \".\",\n]\n\nn_markers = len(markers)\n\nsize = 20 * n_markers, 300\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nplt.axes((0, 0.01, 1, 0.9), frameon=False)\n\nfor i, m in enumerate(markers):\n marker(m, i)\n\nplt.xlim(-0.2, 0.2 + 0.5 * n_markers)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Marker edge color\n\nDemo the marker edge color of matplotlib's markers.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nrng = np.random.default_rng()\n\nfor i in range(1, 11):\n r, g, b = np.random.uniform(0, 1, 3)\n plt.plot(\n [\n i,\n ],\n [\n 1,\n ],\n \"s\",\n markersize=5,\n markerfacecolor=\"w\",\n markeredgewidth=1.5,\n markeredgecolor=(r, g, b, 1),\n )\n\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Marker edge width\n\nDemo the marker edge widths of matplotlib's markers.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nfor i in range(1, 11):\n plt.plot(\n [\n i,\n ],\n [\n 1,\n ],\n \"s\",\n markersize=5,\n markeredgewidth=1 + i / 10.0,\n markeredgecolor=\"k\",\n markerfacecolor=\"w\",\n )\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Marker face color\n\nDemo the marker face color of matplotlib's markers.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nrng = np.random.default_rng()\n\nfor i in range(1, 11):\n r, g, b = np.random.uniform(0, 1, 3)\n plt.plot(\n [\n i,\n ],\n [\n 1,\n ],\n \"s\",\n markersize=8,\n markerfacecolor=(r, g, b, 1),\n markeredgewidth=0.1,\n markeredgecolor=(0, 0, 0, 0.5),\n )\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Marker size\n\nDemo the marker size control in matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nfor i in range(1, 11):\n plt.plot(\n [\n i,\n ],\n [\n 1,\n ],\n \"s\",\n markersize=i,\n markerfacecolor=\"w\",\n markeredgewidth=0.5,\n markeredgecolor=\"k\",\n )\n\nplt.xlim(0, 11)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Solid cap style\n\nAn example demoing the solide cap style in matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.plot(np.arange(4), np.ones(4), color=\"blue\", linewidth=8, solid_capstyle=\"butt\")\n\nplt.plot(\n 5 + np.arange(4), np.ones(4), color=\"blue\", linewidth=8, solid_capstyle=\"round\"\n)\n\nplt.plot(\n 10 + np.arange(4),\n np.ones(4),\n color=\"blue\",\n linewidth=8,\n solid_capstyle=\"projecting\",\n)\n\nplt.xlim(0, 14)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Solid joint style\n\nAn example showing the different solid joint styles in matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nsize = 256, 16\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\nplt.axes((0, 0, 1, 1), frameon=False)\n\nplt.plot(np.arange(3), [0, 1, 0], color=\"blue\", linewidth=8, solid_joinstyle=\"miter\")\nplt.plot(\n 4 + np.arange(3), [0, 1, 0], color=\"blue\", linewidth=8, solid_joinstyle=\"bevel\"\n)\nplt.plot(\n 8 + np.arange(3), [0, 1, 0], color=\"blue\", linewidth=8, solid_joinstyle=\"round\"\n)\n\nplt.xlim(0, 12)\nplt.ylim(-1, 2)\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Locators for tick on axis\n\nAn example demoing different locators to position ticks on axis for\nmatplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n\nfrom matplotlib import ticker\nimport matplotlib.pyplot as plt\n\n\ndef tickline():\n plt.xlim(0, 10), plt.ylim(-1, 1), plt.yticks([])\n ax = plt.gca()\n ax.spines[\"right\"].set_color(\"none\")\n ax.spines[\"left\"].set_color(\"none\")\n ax.spines[\"top\"].set_color(\"none\")\n ax.xaxis.set_ticks_position(\"bottom\")\n ax.spines[\"bottom\"].set_position((\"data\", 0))\n ax.yaxis.set_ticks_position(\"none\")\n ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1))\n ax.plot(np.arange(11), np.zeros(11))\n return ax\n\n\nlocators = [\n \"ticker.NullLocator()\",\n \"ticker.MultipleLocator(1.0)\",\n \"ticker.FixedLocator([0, 2, 8, 9, 10])\",\n \"ticker.IndexLocator(3, 1)\",\n \"ticker.LinearLocator(5)\",\n \"ticker.LogLocator(2, [1.0])\",\n \"ticker.AutoLocator()\",\n]\n\nn_locators = len(locators)\n\nsize = 512, 40 * n_locators\ndpi = 72.0\nfigsize = size[0] / float(dpi), size[1] / float(dpi)\nfig = plt.figure(figsize=figsize, dpi=dpi)\nfig.patch.set_alpha(0)\n\n\nfor i, locator in enumerate(locators):\n plt.subplot(n_locators, 1, i + 1)\n ax = tickline()\n ax.xaxis.set_major_locator(eval(locator))\n plt.text(5, 0.3, locator[7:], ha=\"center\")\n\nplt.subplots_adjust(bottom=0.01, top=0.99, left=0.01, right=0.99)\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Subplots\n",
"\n",
"Show multiple subplots in matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnQAAAHbCAYAAABCywdpAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjYsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvq6yFwwAAAAlwSFlzAAAPYQAAD2EBqD+naQAACkdJREFUeJzt27Fuq1gUQNGLlRant8L/f1gkPsD0ZopRUo0iojw/Z3vWqq/QKTjSxoZp3/d9AACQdXr0AAAA/IygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABD3cuTQ7XYb67qOeZ7HNE33ngkA4H9v3/exbdu4XC7jdPr6N7hDQbeu61iW5Y8MBwDAce/v7+Pt7e3LM4eCbp7nzwuez+efTwYAwJeu1+tYluWzw75yKOg+/mY9n8+CDgDgLzryupuPIgAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIh7OXJo3/cxxhjX6/WuwwAA8K+P7vrosK8cCrpt28YYYyzL8oOxAAD4rm3bxuvr65dnpv1A9t1ut7Gu65jneUzT9McGBADgv+37PrZtG5fLZZxOX78ldyjoAAD4vXwUAQAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAg7uXIodvtNtZ1HfM8j2ma7j0T3M2+72PbtnG5XMbp9PjnGbvFM7BXcB/f2a1DQbeu61iW5Y8MB7/B+/v7eHt7e/QYdounYq/gPo7s1qGgm+f584Ln8/nnk8GDXK/XsSzL5z39aHaLZ2Cv4D6+s1uHgu7jJ+vz+Ww5eAq/5W8Yu8UzsVdwH0d26/EvOwAA8COCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDECToAgDhBBwAQJ+gAAOIEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIA4QQcAECfoAADiBB0AQJygAwCIE3QAAHGCDgAgTtABAMQJOgCAOEEHABAn6AAA4gQdAECcoAMAiBN0AABxgg4AIE7QAQDEvRw5tO/7GGOM6/V612Hg3j7u4Y97+tHsFs/AXsF9fGe3DgXdtm1jjDGWZfnBWPB7bNs2Xl9fHz2G3eKp2Cu4jyO7Ne0Hsu92u411Xcc8z2Oapj82IPxt+76PbdvG5XIZp9Pj3ziwWzwDewX38Z3dOhR0AAD8Xo9/lAIA4EcEHQBAnKADAIgTdAAAcYIOACBO0AEAxAk6AIC4fwDtDPHesVMI6QAAAABJRU5ErkJggg==",
"text/plain": [
"<Figure size 640x480 with 4 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"fig = plt.figure()\n",
"fig.subplots_adjust(bottom=0.025, left=0.025, top=0.975, right=0.975)\n",
"\n",
"plt.subplot(2, 1, 1)\n",
"plt.xticks([]), plt.yticks([])\n",
"\n",
"plt.subplot(2, 3, 4)\n",
"plt.xticks([])\n",
"plt.yticks([])\n",
"\n",
"plt.subplot(2, 3, 5)\n",
"plt.xticks([])\n",
"plt.yticks([])\n",
"\n",
"plt.subplot(2, 3, 6)\n",
"plt.xticks([])\n",
"plt.yticks([])\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Plotting a vector field: quiver\n\nA simple example showing how to plot a vector field (quiver) with\nmatplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nn = 8\nX, Y = np.mgrid[0:n, 0:n]\nT = np.arctan2(Y - n / 2.0, X - n / 2.0)\nR = 10 + np.sqrt((Y - n / 2.0) ** 2 + (X - n / 2.0) ** 2)\nU, V = R * np.cos(T), R * np.sin(T)\n\nplt.axes((0.025, 0.025, 0.95, 0.95))\nplt.quiver(X, Y, U, V, R, alpha=0.5)\nplt.quiver(X, Y, U, V, edgecolor=\"k\", facecolor=\"None\", linewidth=0.5)\n\nplt.xlim(-1, n)\nplt.xticks([])\nplt.ylim(-1, n)\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Subplot grid\n\nAn example showing the subplot grid in matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(6, 4))\nplt.subplot(2, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(2,2,1)\", ha=\"center\", va=\"center\", size=20, alpha=0.5)\n\nplt.subplot(2, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(2,2,2)\", ha=\"center\", va=\"center\", size=20, alpha=0.5)\n\nplt.subplot(2, 2, 3)\nplt.xticks([])\nplt.yticks([])\n\nplt.text(0.5, 0.5, \"subplot(2,2,3)\", ha=\"center\", va=\"center\", size=20, alpha=0.5)\n\nplt.subplot(2, 2, 4)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(2,2,4)\", ha=\"center\", va=\"center\", size=20, alpha=0.5)\n\nplt.tight_layout()\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Horizontal arrangement of subplots\n\nAn example showing horizontal arrangement of subplots with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(6, 4))\nplt.subplot(2, 1, 1)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(2,1,1)\", ha=\"center\", va=\"center\", size=24, alpha=0.5)\n\nplt.subplot(2, 1, 2)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(2,1,2)\", ha=\"center\", va=\"center\", size=24, alpha=0.5)\n\nplt.tight_layout()\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Subplot plot arrangement vertical\n\nAn example showing vertical arrangement of subplots with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\n\nplt.figure(figsize=(6, 4))\nplt.subplot(1, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(1,2,1)\", ha=\"center\", va=\"center\", size=24, alpha=0.5)\n\nplt.subplot(1, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.text(0.5, 0.5, \"subplot(1,2,2)\", ha=\"center\", va=\"center\", size=24, alpha=0.5)\n\nplt.tight_layout()\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo text printing\n\nA example showing off elaborate text printing with matplotlib.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n\neqs = []\neqs.append(\n r\"$W^{3\\beta}_{\\delta_1 \\rho_1 \\sigma_2} = U^{3\\beta}_{\\delta_1 \\rho_1} + \\frac{1}{8 \\pi 2} \\int^{\\alpha_2}_{\\alpha_2} d \\alpha^\\prime_2 \\left[\\frac{ U^{2\\beta}_{\\delta_1 \\rho_1} - \\alpha^\\prime_2U^{1\\beta}_{\\rho_1 \\sigma_2} }{U^{0\\beta}_{\\rho_1 \\sigma_2}}\\right]$\"\n)\neqs.append(\n r\"$\\frac{d\\rho}{d t} + \\rho \\vec{v}\\cdot\\nabla\\vec{v} = -\\nabla p + \\mu\\nabla^2 \\vec{v} + \\rho \\vec{g}$\"\n)\neqs.append(r\"$\\int_{-\\infty}^\\infty e^{-x^2}dx=\\sqrt{\\pi}$\")\neqs.append(r\"$E = mc^2 = \\sqrt{{m_0}^2c^4 + p^2c^2}$\")\neqs.append(r\"$F_G = G\\frac{m_1m_2}{r^2}$\")\n\nplt.axes((0.025, 0.025, 0.95, 0.95))\n\nrng = np.random.default_rng()\n\nfor i in range(24):\n index = rng.integers(0, len(eqs))\n eq = eqs[index]\n size = np.random.uniform(12, 32)\n x, y = np.random.uniform(0, 1, 2)\n alpha = np.random.uniform(0.25, 0.75)\n plt.text(\n x,\n y,\n eq,\n ha=\"center\",\n va=\"center\",\n color=\"#11557c\",\n alpha=alpha,\n transform=plt.gca().transAxes,\n fontsize=size,\n clip_on=True,\n )\nplt.xticks([])\nplt.yticks([])\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Bar plot advanced\n\nAn more elaborate bar plot example\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\nn = 16\nX = np.arange(n)\nY1 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)\nY2 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)\nplt.bar(X, Y1, facecolor=\"#9999ff\", edgecolor=\"white\")\nplt.bar(X, -Y2, facecolor=\"#ff9999\", edgecolor=\"white\")\nplt.xlim(-0.5, n)\nplt.xticks([])\nplt.ylim(-1, 1)\nplt.yticks([])\n\n\n# Add a title and a box around it\nfrom matplotlib.patches import FancyBboxPatch\n\nax = plt.gca()\nax.add_patch(\n FancyBboxPatch(\n (-0.05, 0.87),\n width=0.66,\n height=0.165,\n clip_on=False,\n boxstyle=\"square,pad=0\",\n zorder=3,\n facecolor=\"white\",\n alpha=1.0,\n transform=plt.gca().transAxes,\n )\n)\n\nplt.text(\n -0.05,\n 1.02,\n \" Bar Plot: plt.bar(...)\\n\",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"xx-large\",\n transform=plt.gca().transAxes,\n)\n\nplt.text(\n -0.05,\n 1.01,\n \"\\n\\n Make a bar plot with rectangles \",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"large\",\n transform=plt.gca().transAxes,\n)\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Boxplot with matplotlib\n\nAn example of doing box plots with matplotlib\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n\nfig = plt.figure(figsize=(8, 5))\naxes = plt.subplot(111)\n\nn = 5\nZ = np.zeros((n, 4))\nX = np.linspace(0, 2, n)\nrng = np.random.default_rng()\nY = rng.random((n, 4))\nplt.boxplot(Y)\n\nplt.xticks([])\nplt.yticks([])\n\n\n# Add a title and a box around it\nfrom matplotlib.patches import FancyBboxPatch\n\nax = plt.gca()\nax.add_patch(\n FancyBboxPatch(\n (-0.05, 0.87),\n width=0.66,\n height=0.165,\n clip_on=False,\n boxstyle=\"square,pad=0\",\n zorder=3,\n facecolor=\"white\",\n alpha=1.0,\n transform=plt.gca().transAxes,\n )\n)\n\nplt.text(\n -0.05,\n 1.02,\n \" Box Plot: plt.boxplot(...)\\n \",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"xx-large\",\n transform=axes.transAxes,\n)\n\nplt.text(\n -0.04,\n 0.98,\n \"\\n Make a box and whisker plot \",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"large\",\n transform=axes.transAxes,\n)\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Display the contours of a function\n\nAn example demoing how to plot the contours of a function, with\nadditional layout tweaks.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\n\n\ndef f(x, y):\n return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2) - y**2)\n\n\nn = 256\nx = np.linspace(-3, 3, n)\ny = np.linspace(-3, 3, n)\nX, Y = np.meshgrid(x, y)\n\nplt.contourf(X, Y, f(X, Y), 8, alpha=0.75, cmap=\"hot\")\nC = plt.contour(X, Y, f(X, Y), 8, colors=\"black\", linewidth=0.5)\nplt.clabel(C, inline=1, fontsize=10)\nplt.xticks([])\nplt.yticks([])\n\n\n# Add a title and a box around it\nfrom matplotlib.patches import FancyBboxPatch\n\nax = plt.gca()\nax.add_patch(\n FancyBboxPatch(\n (-0.05, 0.87),\n width=0.66,\n height=0.165,\n clip_on=False,\n boxstyle=\"square,pad=0\",\n zorder=3,\n facecolor=\"white\",\n alpha=1.0,\n transform=plt.gca().transAxes,\n )\n)\n\nplt.text(\n -0.05,\n 1.02,\n \" Contour Plot: plt.contour(..)\\n\",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"xx-large\",\n transform=plt.gca().transAxes,\n)\n\nplt.text(\n -0.05,\n 1.01,\n \"\\n\\n Draw contour lines and filled contours \",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"large\",\n transform=plt.gca().transAxes,\n)\n\nplt.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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Grid elaborate\n\nAn example displaying a grid on the axes and tweaking the layout.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nfrom matplotlib.ticker import MultipleLocator\n\nfig = plt.figure(figsize=(8, 6), dpi=72, facecolor=\"white\")\naxes = plt.subplot(111)\naxes.set_xlim(0, 4)\naxes.set_ylim(0, 3)\n\naxes.xaxis.set_major_locator(MultipleLocator(1.0))\naxes.xaxis.set_minor_locator(MultipleLocator(0.1))\naxes.yaxis.set_major_locator(MultipleLocator(1.0))\naxes.yaxis.set_minor_locator(MultipleLocator(0.1))\naxes.grid(which=\"major\", axis=\"x\", linewidth=0.75, linestyle=\"-\", color=\"0.75\")\naxes.grid(which=\"minor\", axis=\"x\", linewidth=0.25, linestyle=\"-\", color=\"0.75\")\naxes.grid(which=\"major\", axis=\"y\", linewidth=0.75, linestyle=\"-\", color=\"0.75\")\naxes.grid(which=\"minor\", axis=\"y\", linewidth=0.25, linestyle=\"-\", color=\"0.75\")\naxes.set_xticklabels([])\naxes.set_yticklabels([])\n\n\n# Add a title and a box around it\nfrom matplotlib.patches import FancyBboxPatch\n\nax = plt.gca()\nax.add_patch(\n FancyBboxPatch(\n (-0.05, 0.87),\n width=0.66,\n height=0.165,\n clip_on=False,\n boxstyle=\"square,pad=0\",\n zorder=3,\n facecolor=\"white\",\n alpha=1.0,\n transform=plt.gca().transAxes,\n )\n)\n\nplt.text(\n -0.05,\n 1.02,\n \" Grid: plt.grid(...)\\n\",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"xx-large\",\n transform=axes.transAxes,\n)\n\nplt.text(\n -0.05,\n 1.01,\n \"\\n\\n Draw ticks and grid \",\n horizontalalignment=\"left\",\n verticalalignment=\"top\",\n size=\"large\",\n transform=axes.transAxes,\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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

Some files were not shown because too many files have changed in this diff Show More