20 Sep

Hatch, Linestyle, Marker

Matplotlib has many hatches for its bar plots, and many lifestyles and markers for its line plots Sometimes is hard to visualize each "hatch" from just its python syntax. Therefore I created a quick notebook to plot each variable in Matplotlib out. I often come back to these plots to refresh my memory on which hatch is which.


Hatch documentation: Click Here
Marker documentation: Click Here
Linestyle documentation: Click Here

Implement Preliminaries

In [2]:
%matplotlib inline
%config InlineBackend.figure_format='retina'

# Import modules
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# List of matplotlib markers, hatches, and linestyles
hatches = ['/' , '|', '-', '+', 'x', 'o', 'O', '.' ,'*']
linestyles = ['-','--','-.',':']
markers = ['.', ',', 'o', 'v', '^', '<', '>', '1',
           '2', '3', '4', '8', 's', 'p', 'P', '*', 'h',
           'H', '+', 'x', 'X', 'D', 'd', '|', '_', '$yolo $',
           'None']

Visualize Matplotlib Markers

In [3]:
# Plot a line for each marker in our list
for hatch in hatches:
    data = pd.DataFrame(np.random.choice([1,2,3,4], replace=True, size=10), 
                      columns=['Col A'])
    plt.bar(data.index,data['Col A'], hatch=hatch, 
           color='#DE2C26', edgecolor='white')
    plt.title('"'+str(hatch)+'"'+" "+'Hatch Plot')
    plt.ylabel('Y Label')
    plt.xlabel('X Label')
    plt.show()

Visualize Matplotlib Markers

In [4]:
# Plot a line for every linestyle in our list
for line in linestyles:
    data = pd.DataFrame(np.random.choice([1,2,3,4], replace=True, size=10), 
                      columns=['Col A'])
    plt.plot(data.index,data['Col A'], linestyle=line, 
           color='purple', linewidth=3)
    plt.title('"'+str(line)+'" '+'Line Style')
    plt.ylabel('Y Label')
    plt.xlabel('X Label')
    plt.show()

Visualize Matplotlib Markers

In [6]:
# Plot a line for each marker in our list
for mark in markers:
    data = pd.DataFrame(np.random.choice([1,2,3,4], replace=True, size=10), 
                      columns=['Col A'])
    plt.plot(data.index,data['Col A'], marker=mark, 
           color='#31A354', markersize=12)
    plt.title('"'+str(mark)+'"'+" "+'Marker Plot')
    plt.ylabel('Y Label')
    plt.xlabel('X Label')
    plt.show()