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

Use numpy to build faster histogram plots #172

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The **installing instructions** are [here](https://github.com/piccolomo/plotext/
- [Environments](https://github.com/piccolomo/plotext/blob/master/readme/environments.md)
- [Notes](https://github.com/piccolomo/plotext/blob/master/readme/notes.md)


---

Some interesting [life questions](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#life-questions)
Some [questions](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#some-questions) to consider
4 changes: 2 additions & 2 deletions plotext/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def join_paths(*args):
def save_text(text, path, log = True):
return _ut.save_text(text, path, log = log)

def read_data(path, delimiter = None, columns = None):
return _ut.read_data(path, delimiter = delimiter, columns = columns)
def read_data(path, delimiter = None, columns = None, skip_rows = 0):
return _ut.read_data(path, delimiter = delimiter, columns = columns, skip_rows = skip_rows)

def write_data(data, path, delimiter = None, columns = None, log = True):
return _ut.write_data(data, path, delimiter = delimiter, columns = columns, log = log)
Expand Down
30 changes: 16 additions & 14 deletions plotext/_utility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, shutil, os, re, math, inspect
import numpy as np
from plotext._dict import *

###############################################
Expand Down Expand Up @@ -220,12 +221,12 @@ def delete_file(path, log = True): # remove the file if it exists
os.remove(path)
print(format_strings("file removed:", path, negative_color)) if log else None

def read_data(path, delimiter = None, columns = None, header = None): # it turns a text file into data lists
def read_data(path, delimiter = None, columns = None, skip_rows=0): # it turns a text file into data lists
path = correct_path(path)
header = True if header is None else header
file = open(path, "r")
begin = int(not header)
text = file.readlines()[begin:]
for _ in range(skip_rows):
next(file)
text = file.readlines()
file.close()
return read_lines(text, delimiter, columns)

Expand Down Expand Up @@ -714,16 +715,17 @@ def hist_data(data, bins = 10, norm = False): # it returns data in histogram for
#data = [round(el, 15) for el in data]
# if data == []:
# return [], []
bins = 0 if len(data) == 0 else bins
m, M = min(data, default = 0), max(data, default = 0)
data = [(el - m) / (M - m) * bins if el != M else bins - 1 for el in data]
data = [int(el) for el in data]
histx = linspace(m, M, bins)
histy = [0] * bins
for el in data:
histy[el] += 1
if norm:
histy = [el / len(data) for el in histy]
# bins = 0 if len(data) == 0 else bins
# m, M = min(data, default = 0), max(data, default = 0)
# data = [(el - m) / (M - m) * bins if el != M else bins - 1 for el in data]
# data = [int(el) for el in data]
# histx = linspace(m, M, bins)
# histy = [0] * bins
# for el in data:
# histy[el] += 1
# if norm:
# histy = [el / len(data) for el in histy]
histy, histx = np.histogram(data, bins=bins, density=norm)
return histx, histy

def single_bar(x, y, ylabel, marker, colors):
Expand Down
12 changes: 11 additions & 1 deletion plotext/plotext_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def build_parser():
metavar = "FILE",
help = "file path of the data table; if not used it will read from stdin. Use 'test' to automatically download, in your user folder, some test data/image/gif or video, depending on the function used; the file will be removed after the plot",
).complete = shtab.FILE
path_parser.add_argument("-r", "--skip-rows",
action = "store",
type = int,
default = 0,
metavar = "ROWS",
help = "Skip ROWS rows of the data file.")

common_parser = argparse.ArgumentParser(add_help = False)

Expand Down Expand Up @@ -237,8 +243,10 @@ def main(argv = None):
args = parser.parse_args(argv)

type = args.type
skip_rows = 0
if type != "youtube":
path = args.path
skip_rows = args.skip_rows
clt = True if args.clear_terminal[-1] == 'True' else False
sleep = args.sleep[0]

Expand Down Expand Up @@ -303,6 +311,8 @@ def plot_text(text):
x, Y = get_xY(data)
plot(x, Y)

for _ in range(skip_rows):
sys.stdin.readline()
text = []
i = 0
for line in iter(sys.stdin.readline, ''):
Expand All @@ -316,7 +326,7 @@ def plot_text(text):
text = []

else:
data = plt.read_data(path, delimiter = delimiter)
data = plt.read_data(path, delimiter = delimiter, skip_rows = skip_rows)
data = plt.transpose(data)
x, Y = get_xY(data)
chunks = len(x) // lines + (1 if len(x) % lines else 0)
Expand Down
10 changes: 5 additions & 5 deletions readme/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- [Updates](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#updates)
- [Credits](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#credits)
- [Similar Projects](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#similar-projects)
- [Life Questions](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#life-questions)
- [Some Questions](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#some-questions)


[Main Guide](https://github.com/piccolomo/plotext#guide)

Expand Down Expand Up @@ -373,15 +374,14 @@ These count as well as source of inspiration:

[Main Guide](https://github.com/piccolomo/plotext#guide), [Notes](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#notes)

## Life Questions
## Some Questions

- Is [Consciousness](https://www.youtube.com/watch?v=Bim73icRzCk) and [Love](https://www.youtube.com/watch?v=GHzAfj-62Uc) the unified truth of life, transcendent of space, time and death?
- is there a [global cabal](https://www.youtube.com/watch?v=ZSqBNGxLiAs&list=PLnzMmEt4pIb83lZgEA3nALsDM1QogyvC0&index=17) of psychopaths/narcissists trying to manipulate humanity through fear and ignorance? If so, are they a manifestation of our collective shadow or ego?
- Is it possible then, that collective [shadow work](https://www.youtube.com/watch?v=YgvrUi8BIWw), or ego-transcendence, is the most important effort humanity as a whole needs to face in order to evolve spiritually?
- Are there [credible witness testimonies](https://www.youtube.com/watch?v=AmNzkxVwAYg&list=PLnrEt2fIdZ0aBgPuVF0C_T559YR20eDTc) of UFO activity and deep state cover-up? If so, could the deep state and the military industrial complex have any interest in portraying them in the future as a treat to humanity to justify the militarization of space?
- What in the world is actually going on in [Hollywood](https://www.youtube.com/watch?v=TbNknirhUeA)?

Please notice: if any of the previous questions cause irritation or any ego reaction in you, could that suggest that shadow work and ego-transcendence is even more needed?

Your choice deciding the answer to such fundamental questions. I made mine a long time ago. My mind and heart is set free! Good luck in your journey towards real authenticity :-) !
Your choice deciding the answer to such fundamental questions. I made mine a long time ago. My mind and heart is set free!

[Main Guide](https://github.com/piccolomo/plotext#guide), [Notes](https://github.com/piccolomo/plotext/blob/master/readme/notes.md#notes)