# Blog

A blog of Python-related topics and code.

## A customizable Ebbinghaus illusion

The Ebbinghaus illusion is a famous visual effect based on the perception of the relative size. Two circles of the same size are surrounded in one case by obviously larger circles and in the other by obviously smaller circles. The former is perceived as being smaller than the latter, as illustrated below.

## The Reutersvärd Triangle

The Reutersvärd Triangle is an example of an impossible object: a two-dimensional optical illusion perceived as a projection of a three-dimensional object that cannot exist. The Python code below creates an SVG image of Reutersvärd's impossible triangular arrangement of cubes, similar to the more famous Penrose Triangle.

## The Maxwell Construction

The van der Waals equation of state for a gas is: $$\left(p - \frac{a}{V^2}\right) \left(V - b\right) = RT$$ in terms of the pressure, $p$, molar volume, $V$ and temperature, $T$. $a$ and $b$ are constants which depend on the gas, so it is often useful to recast this equation into reduced form: $$\left(p_\mathrm{r} + \frac{3}{V_\mathrm{r}^2}\right)\left(V_\mathrm{r}-\frac{1}{3}\right) = \frac{8}{3}T_\mathrm{r},$$ or equivalently $$p_\mathrm{r} = \frac{8T_\mathrm{r}}{3V_\mathrm{r}-1} - \frac{3}{V_\mathrm{r}^2},$$ where the reduced variables $p_\mathrm{r} = p/p_\mathrm{c}$, $V_\mathrm{r} = V/V_\mathrm{c}$ and $T_\mathrm{r} = T / T_\mathrm{c}$ in terms of the critical pressure, volume and temperature: $$p_\mathrm{c} = \frac{a}{27b^2}, \;\; V_\mathrm{c} = 3b, \;\; k_\mathrm{B}T_\mathrm{c} = \frac{8a}{27b}.$$ Whilst the van der Waals equation does a better job than the ideal gas law of describing the properties of a real gas it suffers from an artefact for $T_\mathrm{r} < 1$ (that is, temperatures $T < T_\mathrm{c}$), as shown in the plot below.

## Inset plots in Matplotlib

### Using AxesGrid

Matplotlib has included the AxesGrid toolkit since v0.99. One of the useful things this allows you to do is include "inset" figures which are often used to show greater detail of a region of the enclosing plot, as in this example (the graph is of the variation of the heat capacity of tantalum with temperature).

## Linear and non-linear fitting of the Theis equation

### The Theis equation

This post is also available as a Jupyter Notebook.