# Example of a scatter plot, with nice serif fonts for both axes labels and tick marks, with ticks plotted on all sides. Also shows some straight lines.

import numpy
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
import random


# Nice fonts
plt.rc('font', family='serif')

# Generate an array of randome values between 0 and 100.
crarray = []

for i in range(100):
	c = int(random.random()*100.0)
	r = int(random.random()*100.0)
	
	# Add the value pair to an array
	crarray.append([c, r])
		
# Convert to numpy. Easier to append to list and then convert here than trying to get numpy to append correctly for some reason !
crarray = numpy.asarray(crarray)


plt.figure(1)

plt.scatter(crarray[:,0], crarray[:,1], color='black')

xlim = 100.0
ylim = 100.0

plt.gca().set_aspect(xlim/ylim, adjustable='box')

axes = plt.gca()
axes.set_xlim([0,xlim])
axes.set_ylim([0,ylim])

XminorLocator = AutoMinorLocator()
YminorLocator = AutoMinorLocator()

axes.xaxis.set_minor_locator(XminorLocator)
axes.yaxis.set_minor_locator(YminorLocator)

# *** TICKS ON ALL AXES, ADJUSTING THEIR SIZE *** 
axes.tick_params(which='minor', bottom=True, top=True, left=True, right=True, length=3)
axes.tick_params(which='major', bottom=True, top=True, left=True, right=True, length=6)


# Add a  solid and a dashed line
plt.plot([0.0,100.0],[0.0,50.0], color='black', linewidth=0.5)	
# Note the adjustment to the `dashes' parameter to adjust the dash length and separation
plt.plot([0.0,100.0],[0.0,(50.0/60.0)*100.0], color='black', linewidth=0.5, linestyle=':', dashes=(5,10))

# *** USE NICE SERIF FONTS FOR BOTH LABELS ***
csfont = {'fontsize':12}
plt.xlabel('Completeness', **csfont)
plt.ylabel('Reliability' , **csfont)

# Alternatively we could have specified something like :
# csfont = {'fontname':'Liberation Serif','fontsize':25}
# But actually ommitting the fontname parameter gives a better default font !

	
plt.savefig('ExampleScatterPLot.png',dpi=150,facecolor='white',bbox_inches='tight')
