Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
furechan committed Sep 27, 2024
1 parent f32bfb2 commit 2ab60c0
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 486 deletions.
313 changes: 313 additions & 0 deletions examples/using-styles.ipynb

Large diffs are not rendered by default.

468 changes: 0 additions & 468 deletions misc/matplotlib-styles.ipynb

This file was deleted.

9 changes: 5 additions & 4 deletions src/mplchart/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from matplotlib import colors as mcolors


def default_edgecolor():
def default_pencolor():
"""default edgecolor to use instead of black"""
facecolor = plt.rcParams["axes.facecolor"]

edgecolor = plt.rcParams["patch.edgecolor"]
if edgecolor != facecolor:
return edgecolor
# color = plt.rcParams["patch.edgecolor"]
color = plt.rcParams["text.color"]
if color != facecolor:
return color

return "black"

Expand Down
12 changes: 6 additions & 6 deletions src/mplchart/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .model import Indicator
from .utils import get_series, series_xy
from .colors import default_edgecolor, closest_color
from .colors import default_pencolor, closest_color


class SMA(Indicator):
Expand Down Expand Up @@ -123,7 +123,7 @@ def plot_result(self, data, chart, ax=None):
label = str(self)
xv, yv = series_xy(data)

color = self.color or default_edgecolor()
color = self.color or default_pencolor()

ax.plot(xv, yv, label=label, color=color)

Expand Down Expand Up @@ -156,7 +156,7 @@ def plot_result(self, data, chart, ax=None):
label = str(self)
xv, yv = series_xy(data)

adxcolor = default_edgecolor()
adxcolor = default_pencolor()

ax.plot(xv, yv, color=adxcolor, label=label)

Expand All @@ -183,7 +183,7 @@ def plot_result(self, data, chart, ax=None):
pdi = data.iloc[:, 1]
ndi = data.iloc[:, 2]

adxcolor = default_edgecolor()
adxcolor = default_pencolor()
pdicolor = closest_color("green")
ndicolor = closest_color("red")

Expand Down Expand Up @@ -227,7 +227,7 @@ def plot_result(self, data, chart, ax=None):
signal = data.iloc[:, 1]
hist = data.iloc[:, 2] * 2.0

edgecolor = default_edgecolor()
edgecolor = default_pencolor()

xv, yv = series_xy(macd)
ax.plot(xv, yv, color=edgecolor, label=label)
Expand Down Expand Up @@ -261,7 +261,7 @@ def plot_result(self, data, chart, ax=None):
signal = data.iloc[:, 1]
hist = data.iloc[:, 2] * 2.0

edgecolor = default_edgecolor()
edgecolor = default_pencolor()

xv, yv = series_xy(ppo)
ax.plot(xv, yv, color=edgecolor, label=label)
Expand Down
4 changes: 2 additions & 2 deletions src/mplchart/primitives/candlesticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from matplotlib.collections import PolyCollection

from ..model import Primitive
from ..colors import default_edgecolor
from ..colors import default_pencolor



Expand Down Expand Up @@ -46,7 +46,7 @@ def plot_handler(self, data, chart, ax=None):

width = self.width

edgecolor = default_edgecolor()
edgecolor = default_pencolor()
facecolor = plt.rcParams["axes.facecolor"]

colorup = self.colorup or edgecolor
Expand Down
6 changes: 3 additions & 3 deletions src/mplchart/primitives/ohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from matplotlib.collections import PolyCollection

from ..model import Primitive
from ..colors import default_edgecolor
from ..colors import default_pencolor


class OHLC(Primitive):
Expand All @@ -32,7 +32,7 @@ def plot_handler(self, data, chart, ax=None):
label = str(self)
data = chart.extract_df(data)

edgecolor = default_edgecolor()
edgecolor = default_pencolor()

width = self.width
colorup = self.colorup or edgecolor
Expand All @@ -46,7 +46,7 @@ def plot_handler(self, data, chart, ax=None):
def plot_ohlc(data, ax=None, width=0.8, colorup=None, colordn=None, label=None):
"""plots open-high-low-close charts as polygons"""

edgecolor = default_edgecolor()
edgecolor = default_pencolor()

colorup = colorup or edgecolor
colordn = colordn or edgecolor
Expand Down
6 changes: 3 additions & 3 deletions src/mplchart/primitives/peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd

from ..model import Primitive

from ..colors import default_pencolor

class Peaks(Primitive):
"""
Expand All @@ -18,7 +18,7 @@ class Peaks(Primitive):

indicator = None

def __init__(self, span=1, *, item: str = None, color: str = "black"):
def __init__(self, span=1, *, item: str = None, color: str = None):
self.span = span
self.color = color
self.item = item
Expand Down Expand Up @@ -49,7 +49,7 @@ def plot_handler(self, data, chart, ax=None):
xv = data.index
yv = data

color = self.color
color = self.color or default_pencolor()

ax.scatter(xv, yv, c=color, s=10 * 10, alpha=0.5, marker=".")

Expand Down

0 comments on commit 2ab60c0

Please sign in to comment.