climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whiteh...@apache.org
Subject [1/2] climate git commit: CLIMATE-586 - add barchart as a plotter option
Date Wed, 08 Apr 2015 14:51:07 GMT
Repository: climate
Updated Branches:
  refs/heads/master d6710a448 -> 5207ddaca


CLIMATE-586 - add barchart as a plotter option

- add draw_barchart function to plotter.py to plot basic
  (horizontal) barchart


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/be11e60a
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/be11e60a
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/be11e60a

Branch: refs/heads/master
Commit: be11e60a4eb1cc79e5414180930edf25d78fb500
Parents: fd4875d
Author: Kim Whitehall <kim.d.whitehall@jpl.nasa.gov>
Authored: Tue Apr 7 06:51:35 2015 -0700
Committer: Kim Whitehall <kim.d.whitehall@jpl.nasa.gov>
Committed: Tue Apr 7 06:51:35 2015 -0700

----------------------------------------------------------------------
 ocw/plotter.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/be11e60a/ocw/plotter.py
----------------------------------------------------------------------
diff --git a/ocw/plotter.py b/ocw/plotter.py
index b931c6c..f40bf14 100644
--- a/ocw/plotter.py
+++ b/ocw/plotter.py
@@ -373,7 +373,7 @@ def draw_time_series(results, times, labels, fname, fmt='png', gridshape=(1,
1),
     :param xlabel: (Optional) x-axis title.
     :type xlabel: :mod:`string`
     
-    :param ylabel: (Optional) y-ayis title.
+    :param ylabel: (Optional) y-axis title.
     :type ylabel: :mod:`string`
 
     :param ptitle: (Optional) plot title.
@@ -488,6 +488,57 @@ def draw_time_series(results, times, labels, fname, fmt='png', gridshape=(1,
1),
     fig.savefig('%s.%s' %(fname, fmt), bbox_inches='tight', dpi=fig.dpi)
     fig.clf()
 
+def draw_barchart(results, yvalues, fname, ptitle='', fmt='png', 
+                     xlabel='', ylabel=''):
+    ''' Draw a barchart.
+
+    :param results: 1D array of  data.
+    :type results: :class:`numpy.ndarray`
+
+    :param yvalues: List of y-axis labels
+    :type times: :class:`list` 
+
+    :param fname: Filename of the plot.
+    :type fname: :mod:`string`
+
+    :param ptitle: (Optional) plot title.
+    :type ptitle: :mod:`string`
+
+    :param fmt: (Optional) filetype for the output.
+    :type fmt: :mod:`string`
+
+    :param xlabel: (Optional) x-axis title.
+    :type xlabel: :mod:`string`
+    
+    :param ylabel: (Optional) y-axis title.
+    :type ylabel: :mod:`string`
+
+    '''
+
+    y_pos = list(range(len(yvalues))) 
+    fig = plt.figure() 
+    fig.set_size_inches((11., 8.5))
+    fig.dpi = 300
+    ax = plt.subplot(111)
+    plt.barh(y_pos, results, align="center", height=0.8, linewidth=0)
+    plt.yticks(y_pos, yvalues)
+    plt.tick_params(axis="both", which="both", bottom="on", top="off",labelbottom="on", left="off",
right="off", labelleft="on")
+    ax.spines["top"].set_visible(False)
+    ax.spines["right"].set_visible(False)
+
+    ymin = min(y_pos) 
+    ymax = max(y_pos)
+    ymin = min((ymin - ((ymax - ymin) * 0.1)/2),0.5) 
+    ymax = ymax + ((ymax - ymin) * 0.1)
+    ax.set_ylim((ymin, ymax))
+    plt.xlabel(xlabel)
+    plt.tight_layout()
+       
+    # Save the figure
+    fig.savefig('%s.%s' %(fname, fmt), bbox_inches='tight', dpi=fig.dpi)
+    fig.clf()
+
+
 def draw_contour_map(dataset, lats, lons, fname, fmt='png', gridshape=(1, 1),
                      clabel='', ptitle='', subtitles=None, cmap=None,
                      clevs=None, nlevs=10, parallels=None, meridians=None,


Mime
View raw message