Violin plots are an alternative to box plots. They show the spread of data in the form of a distribution plot along the y axis. Some people love them. Others don’t! See what you think. Continue reading “52. Matplotlib: Violin plots”
Here will will add contour lines to a heat map.
We’ll use something a little more interesting for the array of values, we’ll define a Mandlebrot fractal function. We have build a 1,000 and 1,000 array and calculate z as a Mandlebrot function of x and y.
The heatmap is drawn with plt.imshow, and then contour lines are added with plt.contour. Continue reading “50. Matplotlib: Adding contour lines to a heatmap”
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
# Set up x any arrays
# scipy linear regression
gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y)
# Calculated fitted y
y_fit=intercept + (x*gradient)
# Plot data
plt.plot(x, y, 'o', label='original data')
plt.plot(x, y_fit, 'r', label='fitted line')
# Add text box and legend
text='Intercept: %.1f\nslope: %.2f\nR-square: %.3f' %(intercept,gradient,r_value**2)
# Display plot
plt.show()Linear regression with scipy.stats
There are various ways of creating subplots in Matplotlib.
Here we will use add_subplot to bring four plots together.
It is also worth looking at subplot2grid if you want plots of different sizes bought together. Continue reading “46. Matplotlib: Creating a grid of subplots”
Heatmaps may be generated with imshow.
We import a colour map from the library cm.
For a list of colour maps available see: https://matplotlib.org/examples/color/colormaps_reference.html Continue reading “45. Matplotlib: A simple heatmap”
Here we show some common modifications to charts. These include:
- Changing scatter plot point style
- Changing line plot line and marker style
- Adding a legend
- Adding some text
- Changing axis scales
- Changing axis ticks
- Adding a grid
- Adding axis tiles
- Adding chart title
Continue reading “44. Matplotlib: Common modifications to charts”
We can create 3D wireframe or surface plots easily in MatplotLib
Continue reading “43. Matplotlib: 3D wireframe and surface plots”
Matplotlib allows easy creation of boxplots. These traditionally show median (middle line across box), uper and lower quartiles (box), range excluding outliers (whiskers) and outliers (points). The default setting for outliers is points more than 1.5xIQR above or below the quartiles.
*IQR = inter-quartile range. Continue reading “42. Matplotlib: Boxplots”