Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add iterable obj processing for xs and ys arguments #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import print_function
import csv
import os
import sys
import optparse
from .utils.helpers import *
Expand Down Expand Up @@ -62,6 +63,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
colour -- colour of the points
title -- title of the plot
"""
path_allowed_types = (str, bytes, os.PathLike)
cs = None
if f:
if isinstance(f, str):
Expand All @@ -73,13 +75,17 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
ys = [float(i[1]) for i in data]
if len(data[0]) > 2:
cs = [i[2].strip() for i in data]
elif isinstance(xs, list) and isinstance(ys, list):
pass
else:
# try to convert any iterable data to list, so we can use any iterable object like pandas dataframe or numpy array
elif type(xs) in path_allowed_types and type(ys) in path_allowed_types:
with open(xs) as fh:
xs = [float(str(row).strip()) for row in fh]
with open(ys) as fh:
ys = [float(str(row).strip()) for row in fh]
elif isiterable(xs) and isiterable(ys):
xs = [i for i in xs]
ys = [i for i in ys]
else:
raise ValueError("Invalid data types {} or {} must be iterable, str, or pathlike".format(type(xs), type(ys)))

_plot_scatter(xs, ys, size, pch, colour, title, cs)

Expand Down