Skip to content

Commit 9d1b93b

Browse files
committed
bar/column chart enhancements
1 parent 14a3d8d commit 9d1b93b

7 files changed

Lines changed: 75 additions & 43 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ Steps to update the version:
2121
In development:
2222
---------------
2323

24-
TODO
24+
TODO.
25+
26+
Version 0.3.4
27+
-------------
28+
29+
New:
30+
31+
* Per-column and per-bar colours in column and bar plots.
32+
33+
Fix:
34+
35+
* Fix bug in column/bar spacing implementation.
2536

2637
Version 0.3.3
2738
-------------

DOCS.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ More plot types:
242242
* Advanced bar charts:
243243
* [x] Bar/column charts with configurable sizes and spacing.
244244
* [ ] Bar/column charts with other alignments.
245+
* [x] Bar/column charts with individual colours.
245246
* [ ] Negative values in bar/column charts.
246247
* Hilbert curves:
247248
* [x] Basic Hilbert curves.
@@ -816,22 +817,24 @@ Inputs:
816817
* color : optional ColorLike.
817818
The color of the filled portion of the bars. Defaults to the terminal's
818819
default foreground color.
820+
* colors : optional ColorLike[n].
821+
The colours of the filled portion of each bar. Should be an array or
822+
list of the same length as `values`.
819823

820824
TODO:
821825

822826
* Make it possible to draw bars to the left for values below 0.
823827
* Make it possible to align all bars to the right rather than left.
824-
* Allow each bar to have its own colour.
825828

826829
### method bars.\_\_repr\_\_
827830

828-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L849))
831+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L856))
829832

830833
---
831834

832835
### class histogram
833836

834-
**histogram(bars):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L857))
837+
**histogram(bars):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L864))
835838

836839
A histogram bar chart.
837840

@@ -868,13 +871,13 @@ Inputs:
868871

869872
### method histogram.\_\_repr\_\_
870873

871-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L928))
874+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L935))
872875

873876
---
874877

875878
### class columns
876879

877-
**columns(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L936))
880+
**columns(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L943))
878881

879882
A column chart.
880883

@@ -902,22 +905,24 @@ Inputs:
902905
* color : optional ColorLike.
903906
The color of the filled portion of the columns. Defaults to the
904907
terminal's default foreground color.
908+
* colors : optional ColorLike[n].
909+
The colours of the filled portion of each column. Should be an array or
910+
list of the same length as `values`.
905911

906912
TODO:
907913

908914
* Make it possible to draw columns downward for values below 0.
909915
* Make it possible to align all columns to the top rather than bottom.
910-
* Allow each column to have its own color.
911916

912917
### method columns.\_\_repr\_\_
913918

914-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1019))
919+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1033))
915920

916921
---
917922

918923
### class vistogram
919924

920-
**vistogram(columns):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1027))
925+
**vistogram(columns):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1041))
921926

922927
A histogram column chart ("vertical histogram", referring to the direction
923928
of the bars rather than the bins).
@@ -955,13 +960,13 @@ Inputs:
955960

956961
### method vistogram.\_\_repr\_\_
957962

958-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1099))
963+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1113))
959964

960965
---
961966

962967
### class hilbert
963968

964-
**hilbert(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1107))
969+
**hilbert(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1121))
965970

966971
Visualize a 1D boolean array along a 2D Hilbert curve.
967972

@@ -981,13 +986,13 @@ Inputs:
981986

982987
### method hilbert.\_\_repr\_\_
983988

984-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1160))
989+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1174))
985990

986991
---
987992

988993
### class text
989994

990-
**text(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1172))
995+
**text(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1186))
991996

992997
A plot object containing one or more lines of text.
993998

@@ -1014,13 +1019,13 @@ TODO:
10141019

10151020
### method text.\_\_repr\_\_
10161021

1017-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1226))
1022+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1240))
10181023

10191024
---
10201025

10211026
### class border
10221027

1023-
**border(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1233))
1028+
**border(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1247))
10241029

10251030
Add a border around a plot using box-drawing characters.
10261031

@@ -1039,13 +1044,13 @@ Inputs:
10391044

10401045
### method border.\_\_repr\_\_
10411046

1042-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1269))
1047+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1283))
10431048

10441049
---
10451050

10461051
### class axes
10471052

1048-
**axes(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1273))
1053+
**axes(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1287))
10491054

10501055
Add an annotated border around a 2d plot using box-drawing characters.
10511056

@@ -1079,13 +1084,13 @@ Inputs:
10791084

10801085
### method axes.\_\_repr\_\_
10811086

1082-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1353))
1087+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1367))
10831088

10841089
---
10851090

10861091
### class blank
10871092

1088-
**blank(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1361))
1093+
**blank(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1375))
10891094

10901095
Creates a rectangular plot composed entirely of blank space.
10911096

@@ -1100,13 +1105,13 @@ Inputs:
11001105

11011106
### method blank.\_\_repr\_\_
11021107

1103-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1382))
1108+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1396))
11041109

11051110
---
11061111

11071112
### class hstack
11081113

1109-
**hstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1386))
1114+
**hstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1400))
11101115

11111116
Horizontally arrange one or more plots side-by-side.
11121117

@@ -1120,13 +1125,13 @@ Inputs:
11201125

11211126
### method hstack.\_\_repr\_\_
11221127

1123-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1411))
1128+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1425))
11241129

11251130
---
11261131

11271132
### class vstack
11281133

1129-
**vstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1418))
1134+
**vstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1432))
11301135

11311136
Vertically arrange one or more plots, one above the other.
11321137

@@ -1140,13 +1145,13 @@ Inputs:
11401145

11411146
### method vstack.\_\_repr\_\_
11421147

1143-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1443))
1148+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1457))
11441149

11451150
---
11461151

11471152
### class dstack
11481153

1149-
**dstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1450))
1154+
**dstack(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1464))
11501155

11511156
Overlay one or more plots on top of each other.
11521157

@@ -1162,13 +1167,13 @@ Inputs:
11621167

11631168
### method dstack.\_\_repr\_\_
11641169

1165-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1488))
1170+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1502))
11661171

11671172
---
11681173

11691174
### class dstack2
11701175

1171-
**dstack2(dstack):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1495))
1176+
**dstack2(dstack):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1509))
11721177

11731178
Overlay one or more plots on top of each other.
11741179

@@ -1189,13 +1194,13 @@ Inputs:
11891194

11901195
### method dstack2.\_\_repr\_\_
11911196

1192-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1533))
1197+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1547))
11931198

11941199
---
11951200

11961201
### class wrap
11971202

1198-
**wrap(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1540))
1203+
**wrap(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1554))
11991204

12001205
Arrange a sequence of plots into a grid.
12011206

@@ -1218,13 +1223,13 @@ Inputs:
12181223

12191224
### method wrap.\_\_repr\_\_
12201225

1221-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1608))
1226+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1622))
12221227

12231228
---
12241229

12251230
### class center
12261231

1227-
**center(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1615))
1232+
**center(plot):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1629))
12281233

12291234
Pad a plot with blank space to center it within a larger area.
12301235

@@ -1245,13 +1250,13 @@ Inputs:
12451250

12461251
### method center.\_\_repr\_\_
12471252

1248-
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1667))
1253+
**\_\_repr\_\_():** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1681))
12491254

12501255
---
12511256

12521257
### function save\_animation
12531258

1254-
**save\_animation(plots: Sequence[plot], filename: str, upscale: int, downscale: int, bgcolor: ColorLike | None, fps: int, repeat: bool):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1678))
1259+
**save\_animation(plots: Sequence[plot], filename: str, upscale: int, downscale: int, bgcolor: ColorLike | None, fps: int, repeat: bool):** ([source](https://github.com/matomatical/matthewplotlib/blob/main/matthewplotlib/plots.py#L1692))
12551260

12561261
Supply a list of plots and a filename and this method will create an
12571262
animated gif.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ More plot types:
242242
* Advanced bar charts:
243243
* [x] Bar/column charts with configurable sizes and spacing.
244244
* [ ] Bar/column charts with other alignments.
245+
* [x] Bar/column charts with individual colours.
245246
* [ ] Negative values in bar/column charts.
246247
* Hilbert curves:
247248
* [x] Basic Hilbert curves.

examples/dashboard.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ def main():
6464
cpu_percents_core,
6565
height=left_panel.height - 3,
6666
vrange=100,
67-
column_width=2,
68-
color="yellow"
67+
column_width=1,
68+
column_spacing=1,
69+
colors=mp.rainbow(np.linspace(0,1,len(cpu_percents_core))),
6970
))
7071
core_title = mp.center(
7172
mp.text("CPU Core Usage"),

matthewplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66

7-
__version__ = "0.3.3"
7+
__version__ = "0.3.4"
88

99

1010
from matthewplotlib.plots import (

0 commit comments

Comments
 (0)