0
|
1 """
|
|
2 Author: Timothy Tickle
|
|
3 Description: Class to create scatter plots.
|
|
4 """
|
|
5
|
|
6 #####################################################################################
|
|
7 #Copyright (C) <2012>
|
|
8 #
|
|
9 #Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
10 #this software and associated documentation files (the "Software"), to deal in the
|
|
11 #Software without restriction, including without limitation the rights to use, copy,
|
|
12 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
13 #and to permit persons to whom the Software is furnished to do so, subject to
|
|
14 #the following conditions:
|
|
15 #
|
|
16 #The above copyright notice and this permission notice shall be included in all copies
|
|
17 #or substantial portions of the Software.
|
|
18 #
|
|
19 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
20 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
21 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25 #####################################################################################
|
|
26
|
|
27 __author__ = "Timothy Tickle"
|
|
28 __copyright__ = "Copyright 2012"
|
|
29 __credits__ = ["Timothy Tickle"]
|
|
30 __license__ = "MIT"
|
|
31 __maintainer__ = "Timothy Tickle"
|
|
32 __email__ = "ttickle@sph.harvard.edu"
|
|
33 __status__ = "Development"
|
|
34
|
|
35 #External libraries
|
|
36 from ConstantsFiguresBreadCrumbs import ConstantsFiguresBreadCrumbs
|
|
37 import matplotlib.pyplot as plt
|
|
38 from pylab import *
|
|
39
|
|
40 #Plots a matrix
|
|
41 class ScatterPlot:
|
|
42
|
|
43 @staticmethod
|
|
44 def funcPlot(lx, ly, strOutputFigurePath, strTitle = "Title", strXTitle="X Axis", strYTitle="Y Axis", strColor = "#83C8F9", fInvert=False):
|
|
45 """
|
|
46 Plot a scatter plot.
|
|
47
|
|
48 :params lx: List of x values
|
|
49 :type: List of doubles
|
|
50 :params ly: List of y values
|
|
51 :type: List of doubles
|
|
52 :params strOutputFigurePath: File path to make figure
|
|
53 :type: String file path
|
|
54 :params strTitle: Title of figure
|
|
55 :type: String
|
|
56 :params strXTitle: Label of x axis
|
|
57 :type: String
|
|
58 :params strYTitle: Label of y axis
|
|
59 :type: String
|
|
60 :params strColor: Hex color for the face of the boxplots
|
|
61 :type: String
|
|
62 :params fInvert: Invert colors (true)
|
|
63 :type: Boolean
|
|
64 """
|
|
65
|
|
66 #Start plot
|
|
67 #Get plot object
|
|
68 imgFigure = plt.figure()
|
|
69
|
|
70 #Get plot colorsstrOutFigure
|
|
71 objFigureControl = ConstantsFiguresBreadCrumbs()
|
|
72 #Boxplots have to be plotted over the scatter so the alpha can not go to 1.0
|
|
73 #In this case capturing the alpha before inversion
|
|
74 #Inversion automoatically sets it to 1.
|
|
75 dAlpha=objFigureControl.c_dAlpha
|
|
76 objFigureControl.invertColors(fInvert=fInvert)
|
|
77
|
|
78 #Color/Invert figure
|
|
79 imgFigure.set_facecolor(objFigureControl.c_strBackgroundColorWord)
|
|
80 imgSubplot = imgFigure.add_subplot(111,axisbg=objFigureControl.c_strBackgroundColorLetter)
|
|
81 imgSubplot.set_xlabel(strXTitle)
|
|
82 imgSubplot.set_ylabel(strYTitle)
|
|
83 imgSubplot.spines['top'].set_color(objFigureControl.c_strDetailsColorLetter)
|
|
84 imgSubplot.spines['bottom'].set_color(objFigureControl.c_strDetailsColorLetter)
|
|
85 imgSubplot.spines['left'].set_color(objFigureControl.c_strDetailsColorLetter)
|
|
86 imgSubplot.spines['right'].set_color(objFigureControl.c_strDetailsColorLetter)
|
|
87 imgSubplot.xaxis.label.set_color(objFigureControl.c_strDetailsColorLetter)
|
|
88
|
|
89 #Adds light grid for numbers and puts them in the background
|
|
90 imgSubplot.yaxis.grid(True, linestyle='-', which='major', color=objFigureControl.c_strGridLineColor, alpha=objFigureControl.c_dAlpha)
|
|
91 imgSubplot.set_axisbelow(True)
|
|
92 imgSubplot.yaxis.label.set_color(objFigureControl.c_strDetailsColorLetter)
|
|
93 imgSubplot.tick_params(axis='x', colors=objFigureControl.c_strDetailsColorLetter)
|
|
94 imgSubplot.tick_params(axis='y', colors=objFigureControl.c_strDetailsColorLetter)
|
|
95 charMarkerEdgeColor = objFigureControl.c_strDetailsColorLetter
|
|
96
|
|
97 #Make scatter plot
|
|
98 plt.scatter(x=lx,y=ly,c=strColor,marker="o",alpha=objFigureControl.c_dAlpha)
|
|
99
|
|
100 #Set ticks and title
|
|
101 imgSubplot.set_title(strTitle)
|
|
102 imgSubplot.title.set_color(objFigureControl.c_strDetailsColorLetter)
|
|
103
|
|
104 #End plot
|
|
105 #Save to a file
|
|
106 imgFigure.savefig(strOutputFigurePath, facecolor=imgFigure.get_facecolor())
|