112 Data Visualizations
112.10 Data visualization with python

Data visualization with python

These notes were cut short because I found it much more valuable to do the visualizations than write about them. See Redata, Blog, for some examples.

Graph size

To make a bigger graph, set this param
plt.rcParams["figure.figsize"] = (20, 10)

And, to set it back to the default"default")


To create a matrix plot of 1's and 0's

import pandas as pd
import numpy as np

# first make a dataframe with random 1's and 0's
df = pd.DataFrame(np.random.randint(0, 2, size=(100,4)), columns=list('1234'))

# then plot it
plt.imshow(df, cmap='GnBu')

This code also adds the grid lines in-between the dots

im = plt.imshow(df, cmap='GnBu')
ax = plt.gca()
ax.set_xticks(np.arange(-0.5, len(df.columns), 1), minor=True)
ax.set_yticks(np.arange(-0.5, len(df.index), 1), minor=True)
ax.grid(which='minor', color='w', linestyle='-', linewidth=2)


  • Me