Skip to content

Commit

Permalink
added version 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
piccolomo committed Sep 24, 2022
1 parent 1da9ae6 commit 863a352
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plotext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from plotext._core import *

__name__ = "plotext"
__version__ = "4.1.5"
__version__ = "4.2.0"
6 changes: 4 additions & 2 deletions plotext/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,24 @@ def stacked_bar(x, y,

def hist(data,
bins = None,
width = None,
norm = False,
yside = None,
xside = None,
marker = None,
color = None,
fill = True,
width = None,
orientation = None,
label = None):
figure.subplot.draw_hist(data,
bins = bins,
width = width,
norm = norm,
xside = xside,
yside = yside,
marker = marker,
color = color,
fill = fill,
width = width,
orientation = orientation,
label = label)

Expand Down
3 changes: 2 additions & 1 deletion plotext/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from plotext._matrices import figure_matrices
from plotext._default import figure_default
from plotext._utility.file import save_text
from plotext._subplot import datetime as _datetime
from plotext._subplot import subplot_class
from plotext._utility.plot import *
from time import time
Expand Down Expand Up @@ -227,7 +228,7 @@ def xticks(self, ticks = None, labels = None, xside = None):
ticks = self.subplot.default.xticks[pos] if ticks is None else list(ticks)
labels = ticks if labels is None else list(labels)
labels = list(map(str, labels))
ticks = list(map(_utility.string_to_time, ticks)) if len(ticks) > 0 and type(ticks[0]) == str else ticks
ticks = list(map(_datetime.string_to_timestamp, ticks)) if len(ticks) > 0 and type(ticks[0]) == str else ticks
ticks, labels = brush(ticks, labels)
self.subplot.xticks[pos] = ticks
self.subplot.xlabels[pos] = labels
Expand Down
7 changes: 5 additions & 2 deletions plotext/_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,13 @@ def draw_single_bar(self, x, y, **kwargs):
self.xlim[xpos] = self.bar_ylim
self.bar_xlim = update_bar_xlim(self.bar_xlim + self.ylim[ypos] + xticks + join(ybar))
self.ylim[ypos] = self.bar_xlim

firstbar = min([b for b in range(len(x)) if ybar[b][1] != 0], default = 0) # finds the position of the first non zero bar

for b in range(len(x)):
xb = xbar[b][1:3] if fill else xbar[b]
yb = ybar[b][1:3] if fill else ybar[b]
plot_label = label if b == 0 else None
plot_label = label if b == firstbar else None
plot_color = color if b == 0 else self.color[-1]
nobar = (yb[1] == 0 and orientation[0] == 'v') or (xb[1] == 0 and orientation[0] == 'h')
plot_marker = " " if nobar else marker
Expand Down Expand Up @@ -548,7 +550,8 @@ def draw_stacked_bar(self, x, y, **kwargs):
def draw_hist(self, data, **kwargs):
bins = kwargs.get("bins")
bins = self.default.hist_bins if bins is None else bins
x, y = hist_data(data, bins)
norm = kwargs.get("norm", False)
x, y = hist_data(data, bins, norm)
self.draw_single_bar(x, y, **kwargs)

def draw_matrix(self, matrix, **kwargs):
Expand Down
8 changes: 5 additions & 3 deletions plotext/_utility/bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from plotext._utility.plot import get_labels
from plotext._utility.data import linspace
from plotext._utility.data import linspace, get_lim

##############################################
############ Bar Functions ##############
Expand All @@ -24,7 +24,7 @@ def update_bars(x, bars, offset): # it updates the bar coordinates using the pas

def update_bar_xlim(y): # it updates the bar limits along their base dimension (x if orientation is vertical otherwise y)
y = [el for el in y if el is not None]
bar_lim = [min(y, default = None), max(y, default = None)]
bar_lim = get_lim(y)
return bar_lim

def update_bar_ylim(y): # it updates the bar limits along their heights (y if orientation is vertical otherwise x)
Expand Down Expand Up @@ -56,7 +56,7 @@ def bars(x, y, width, minimum): # given the bars center coordinates and height,
########### Hist Functions ##############
##############################################

def hist_data(data, bins = 10): # it returns data in histogram form
def hist_data(data, bins = 10, norm = False): # it returns data in histogram form if norm is False. Otherwise, it returns data in density form where all bins sum to 1.
#data = [round(el, 15) for el in data]
if data == []:
return [], []
Expand All @@ -67,4 +67,6 @@ def hist_data(data, bins = 10): # it returns data in histogram form
histy = [0] * bins
for el in data:
histy[el] += 1
if norm:
histy = [el / len(data) for el in histy]
return histx, histy
5 changes: 3 additions & 2 deletions plotext/_utility/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@
It accepts the same parameters as the bar() function."""
stacked_bar = lambda: print(_stacked_bar)

_hist = """It builds the histogram plot relative to the data provided. It accepts the same parameters as the bar plot (except for 'minimum' which is not available here) with the following extra parameter:
_hist = """It builds the histogram plot relative to the data provided. It accepts the same parameters as the bar plot (except for 'minimum' which is not available here) with the following extra parameters:
\x1b[96mbins\x1b[0m used to calculate the histogram transform of the data (10 by default)."""
\x1b[96mbins\x1b[0m used to calculate the histogram transform of the data (10 by default).
\x1b[96mnorm\x1b[0m if True, the bin heights are normalised so that the plot would simulate a probability distribution."""
hist = lambda: print(_hist)

##############################################
Expand Down
4 changes: 2 additions & 2 deletions plotext/_utility/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def platform(): # the platform (eg: linux) you are using plotext with
import subprocess
subprocess.call('', shell = True)

import win_unicode_console
win_unicode_console.enable()
#import win_unicode_console
#win_unicode_console.enable()

#to enable higher definition markers in windows: it didn't work....
#import ctypes
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
author = "Savino Piccolomo",
author_email = "[email protected]",
name = 'plotext',
version='4.1.5',
version='4.2.0',
description = 'plotext plots directly on terminal',
long_description = README,
long_description_content_type = "text/markdown",
Expand Down

0 comments on commit 863a352

Please sign in to comment.