Visit
http://datamatrix.cogsci.nl/plotting
for the latest documentation
Plotting
Compatibility with Seaborn and Matplotlib
DataMatrix
objects can be passed to most seaborn
plotting functions as if they are pandas.DataFrame
objects. Below are some examples of common plot types.
The example data1 below is from a behavioral experiment with a single dependent variable (RT_search
) and two independent variables (condition
and load
).
from datamatrix import io
from matplotlib import pyplot as plt
import seaborn as sns
dm = io.readtxt('data/fratescu-replication-data-exp1.csv')
sns.set(style='darkgrid')
Point plot
Seaborn documentation:
plt.clf()
sns.pointplot(
x='condition',
y='RT_search',
hue='load',
order=['no', 'unrel', 'rel-mis', 'rel-match'],
data=dm,
)
plt.xlabel('Distractor condition')
plt.ylabel('Reaction time (ms)')
plt.legend(title='Memory load')
plt.savefig('content/pages/img/plotting/pointplot.png')
Bar plot (sns.barplot)
Seaborn documentation:
plt.clf()
sns.barplot(
x='condition',
y='RT_search',
hue='load',
order=['no', 'unrel', 'rel-mis', 'rel-match'],
data=dm,
)
plt.ylim(700, 900)
plt.xlabel('Distractor condition')
plt.ylabel('Reaction time (ms)')
plt.legend(title='Memory load')
plt.savefig('content/pages/img/plotting/barplot.png')
Distribution plot (sns.distplot)
Seaborn documentation:
plt.clf()
sns.distplot(dm.RT_search)
plt.savefig('content/pages/img/plotting/distplot.png')
-
The example data is adapted from Frătescu et al. (2018), Experiment 1. ↩