Graphing Matplotlib Python Part 3: Colors and Line Thickness

How to do some basic Matplotlib customization




Once you've got the basics down, you'll probably want to learn how to customize the charts a bit. By default, the Matplotlib charts are rather bland, but the creator of Matplotlib left the door wide open to customization. In this tutorial, we'll just do a simple change of color to the line, as well as adjust the thickness of the line.

These are just two extremely basic customization options, there are many more for us to cover.

import matplotlib.pyplot as plt

x = []
y = []

fig = plt.figure()
rect = fig.patch
rect.set_facecolor('#31312e')

readFile = open('SampleData.txt','r')
sepFile = readFile.read().split('\n')
readFile.close()

for plotPair in sepFile:
    xAndY = plotPair.split(',')
    x.append(int(xAndY[0]))
    y.append(int(xAndY[1]))

ax1 = fig.add_subplot(1,1,1, axisbg='grey')
ax1.plot(x, y, 'c', linewidth=3.3)

plt.show()   
	  

Fore more tutorials, head to the