Draw axes in axes using zoomed_inset_axes, python and matplotlib.pyplot


The result is:


This page shows how to draw an axes in another axes using zoomed_insed_axes of the matplotlib toolkits.

Change hatch density in barplot of Python Matplotlib.pyplot


The result is:

Change hatch density of barplot python matolotlib pyplot

This page shows how to increase the hatch density in barplot of matplotlib.
By changing the hatch string, you can change the hatch density.

Try all legend options in Python Matplotlib.pyplot


The default legend is:

Try all legend options - default result -

In this page, all legend options are tried.

Create animation of plt.contourf for visualize air flow past three cylinders using Python Matplotlib.pyplot and Matplotlib.animation.ArtistAnimation


The result is:

This page shows my exercise to visualize air flow past three cylinders.
The flow is calculated by commercial finite elemental method software i.e. COMSOL Multiphysics.
In this code, matplotlib.animation.ArtistAnimation function is used.

Simple way to draw electric field lines using Plotly.offline; convert from Matplotlib.pyplot


The result is:


This page shows how to draw vector field (electric field lines) using plotly. The figure is converted from matplotlib.pyplot.

Draw cycloid animation using matplotlib.animation.ArtistAnimation


The result is:
Draw cycloid animation using matplotlib.animation.ArtistAnimation

In this page, an animation of cycloid is generated using ArtistAnimation function of matplotlib.animation.
The animation of cycloid is already generated in "Draw cycloid animation using matplotlib.animation.FuncAnimation".
Here, an altanative way for drawing animations that is matplotlib.animation.ArtistAnimation is used.
I think ArtistAnimation is easier to understand and write the code than FucAnimation.

Draw 3D line animation using Python Matplotlib.ArtistAnimation


The result is:

Draw 3D line animation using Python Matplotlib.ArtistAnimation

This page shows how to draw 3D line animation using python & matplotlib. Note that you must install ffmpeg and imagemagick to properly display the result.

Draw 3D line animation using Python Matplotlib.FuncAnimation


The result is:

Draw 3D line animation using Python Matplotlib.FuncAnimation

This page shows how to draw 3D line animation using python & matplotlib. Note that you must install ffmpeg and imagemagick to properly display the result.


Better way to chose numbers of x and y ticklabels in Python Matplotlib.pyplot


The result is:

Better way to chose numbers of x and y ticklabels in Python Matplotlib.pyplot

This page shows the better way to chose numbers of x and y ticklabels.

Arrange multiple images in one large image using Python PIL.Image


The results are:

Arrange multiple images in one large image using Python PIL.Image -1-

and

Arrange multiple images in one large image using Python PIL.Image -2-

This page shows how to arrange the images in one figure using Python & PIL.Image.

Draw electric field lines without Mayavi


The result is:

Draw electric field lines without Mayavi

Plot on an image using Python Matplotlib.pyplot


The result is:

Plot on an image using Python Matplotlib.pyplot

This page shows how to plot data on an image.
plt.plot and plt.scatter is used in this page as an example.
You can plot by mapping function that convert the point of the plotting data to that of the image.

Draw cycloid animation using matplotlib.animation.FuncAnimation


The result is:

Draw cycloid animation using matplotlib.animation.FuncAnimation

This page shows an example of the animation.FuncAnimation function. The theme is the animation of the cycloid.

Speed up plotting magnified waveforms using Python & Matplotlib.pyplot


We can reduce the calculation time as the orange line in the following figure:


This page shows how to speed up plotting magnified waveforms in matplotlib.
By limiting the data before plotting, we can improve the performance of the matplotlib.
Especially, this method is suitable when the data range for plot is very short compared with the whole data range.

Change the space between labels and lines of the legend in Python Matplotlib.pyplot


The result is:

Legend with changing padding between line and label using handletextpad option

This page how to change the space between the lines in legend and their labels.

Draw electric field lines with changing line color according to the electric potential



The results are:




This page shows how to draw electric force lines around point charges.
The colors of the electric force lines vary according to the electric potential in the point.

Draw flow past cylinder with continuous stream line using Python Matplotlib.pyplot


The result is:


This page shows how to plot air flow past a cylinder with continuous streamline or how to plot vecter field with continuous streamline. The air flow i.e. vecter field is calculated using COMSOL Multiphysics.

Plot continuous magnetic field lines using Python Matplotlib.pyplot


The result is:

Plot continuous magnetic field lines using Python Matplotlib.pyplot

This page introduces how to replot the normal stremplot or stremaline with continuous streamplot or stremline.

Plot electric field lines around a point charge with grounded sphere using Python Matplotlib.pyplot


The result is :


This page shows the method to draw electric field line around a point charge adjecent to a grounded sphere using method of image charges.

Draw electric field lines due to point charges using Python Matplotlib.pyplot


The results are:


and


This code shows how to visualize streamlines with continuous lines using python and matplotlib.pyplot.

When you search "electric field lines python" or something in Google, you would see the images which use the streamplot. Although it is easy way to visualize the direction of the vector fields, electric field must be continuous lines as you know. In this page, electric field lines around the point charges are calculated using scipy.ode (ordinary differential equations) module.

This code is based on following wonderful tips blog posts:



The effect of pad_inches in Python Matplotlib.pyplot


The results are:





This page shows how to change pad_inches and how it affect on the saved figure in python and matplotlib.pyplot.

Display same figure with changing lines color and math fonts


The example of the result (computer modern) is:



This page show how to display several font all at once.
Computer modern, stix (Times New Roman), arial, cambria and arial (with colored line) are displayed.

Draw minor ticks at arbitrary place using Python Matplotlib.pyplot

In [1]:
import matplotlib.pyplot as plt
import numpy as np
from itertools import product
from matplotlib import ticker
%matplotlib inline
In [2]:
plt.figure(figsize=(4,3),facecolor="w")
plt.plot([0,1],[0,1])
minors = [0.1,0.12,0.125,0.15,0.16,0.17,0.18,0.19]
plt.axes().xaxis.set_minor_locator(ticker.FixedLocator(minors))
plt.tick_params(which='minor', length=3, color='r')
In [3]:
plt.figure(figsize=(4,3),facecolor="w")
plt.plot(np.log10([1,100]),np.log10([1,100]))
xtks = np.array([1,10,100])
xtkp = np.log10(xtks)
plt.axes().set_xticks(xtkp)
plt.axes().set_xticklabels(xtks)
ytks = np.array([1,10,100])
ytkp = np.log10(ytks)
plt.axes().set_yticks(ytkp)
plt.axes().set_yticklabels(ytks)
xminors = np.log10([2,3,5,20,30,40,50,60,70,80,90])
yminors = np.log10(([k*m for k,m in product([2,3,4,5,6,7,8,9],[1,10])]))
plt.axes().xaxis.set_minor_locator(ticker.FixedLocator(xminors))
plt.axes().yaxis.set_minor_locator(ticker.FixedLocator(yminors))
plt.tick_params(which='minor', length=3, color='k')

Draw animation graph using Python Matplotlib.pyplot


The result is:

Draw animation graph using Python Matplotlib.pyplot

This page shows an example of the animation generated by the matplotlib.pyplot of python.