diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b321a22 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +MIT License + + Copyright (c) 2014 Ian Horn and + Danilo J. S. Bellini + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index f6b4e57..5612ae4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ hipsterplot =========== +[![PyPI](https://img.shields.io/pypi/v/hipsterplot)](https://pypi.org/project/hipsterplot/) +[![PyPI - License](https://img.shields.io/pypi/l/hipsterplot)](https://opensource.org/licenses/MIT) + because matplotlib is too mainstream (or you broke it like I did). Also good while debugging numerical code. ----------------------------------- @@ -9,7 +12,7 @@ A python script for command line plotting. `pip install hipsterplot` is all you need. -Can plot a list of y values [ys] which works for evenly spaced points, or pairs of lists ([xs], [ys]) which works for heterogeneous x-spacing, or disorder in the x's (scatterplots). +Can plot a list of y values \[ys\] which works for evenly spaced points, or pairs of lists (\[xs\], \[ys\]) which works for heterogeneous x-spacing, or disorder in the x's (scatterplots). In a given 'pixel', the plotted character depends how many data points map to it, so it can look good on densities. diff --git a/hipsterplot.py b/hipsterplot.py index 38b5c94..a744cee 100755 --- a/hipsterplot.py +++ b/hipsterplot.py @@ -25,7 +25,7 @@ # SOFTWARE. from __future__ import print_function, division -import math, random, sys +import math, random, sys, os from operator import itemgetter # Python 2.x and 3.x compatibility @@ -37,9 +37,9 @@ CHAR_LOOKUP_SYMBOLS = [(0, ' '), # Should be sorted (1, '.'), (2, ':'), - #(3, '!'), + (3, '!'), (4, '|'), - #(8, '+'), + (8, '+'), (float("inf"), '#')] def charlookup(num_chars): @@ -73,15 +73,7 @@ def enumerated_reversed(seq): return zip(range(len(seq) - 1, -1, -1), reversed(seq)) -def plot(y_vals, x_vals=None, num_x_chars=70, num_y_chars=15): - """ - Plots the values given by y_vals. The x_vals values are the y indexes, by - default, unless explicitly given. Pairs (x, y) are matched by the x_vals - and y_vals indexes, so these must have the same length. - - The num_x_chars and num_y_chars inputs are respectively the width and - height for the output plot to be printed, given in characters. - """ +def gen_plot(y_vals, x_vals=None, num_x_chars=70, num_y_chars=15): y_vals = list(y_vals) x_vals = list(x_vals) if x_vals else list(range(len(y_vals))) if len(x_vals) != len(y_vals): @@ -106,7 +98,20 @@ def plot(y_vals, x_vals=None, num_x_chars=70, num_y_chars=15): for idx, row in enumerated_reversed(rows): y_bin_mid = y_bin_ends[idx] - y_bin_width * 0.5 - print("{:10.4f} {}".format(y_bin_mid, "".join(row))) + lines = "{:10.4f} {}".format(y_bin_mid, "".join(row)) + return os.linesep.join([line.rstrip() for line in lines.split(os.linesep)]) + + +def plot(y_vals, x_vals=None, num_x_chars=70, num_y_chars=15): + """ + Plots the values given by y_vals. The x_vals values are the y indexes, by + default, unless explicitly given. Pairs (x, y) are matched by the x_vals + and y_vals indexes, so these must have the same length. + + The num_x_chars and num_y_chars inputs are respectively the width and + height for the output plot to be printed, given in characters. + """ + print(gen_plot(y_vals, x_vals, num_x_chars, num_y_chars)) if __name__ == '__main__': @@ -123,4 +128,4 @@ def plot(y_vals, x_vals=None, num_x_chars=70, num_y_chars=15): k = 20 ys = [random.gauss(0, 0.5) + math.cos(x/5.0/k) for x in range(180*k)] num_x_chars = min(160, len(ys)) - plot(ys, num_x_chars=num_x_chars, num_y_chars=25) \ No newline at end of file + plot(ys, num_x_chars=num_x_chars, num_y_chars=25) diff --git a/setup.py b/setup.py index 2867617..9aaf73d 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ metadata = { "name": "hipsterplot", - "version": "0.1", + "version": "0.1.1", "author": "Ian Horn and Danilo J. S. Bellini", "author_email": "horn.imh@gmail.com ; danilo.bellini.gmail.com", "url": "http://github.com/imh/hipsterplot",