mplfinance\plotting.py", line 1108, in _addplot_columns
ymhi = math.log(max(math.fabs(np.nanmax(yd)),1e-7),10)
This Numpy code generates an error.
"ValueError: zero-size array to reduction operation maximum which has no identity"
Error reproduction
import datetime
import numpy as np
import pandas as pd
import mplfinance as mpf
# ランダムなOHLCデータを生成する関数
def generate_sample_ohlc_data(n=10):
# 現在の日付を取得
base_date = datetime.datetime.now()
# 日付のリストを生成
dates = [base_date - datetime.timedelta(days=i) for i in range(n)]
dates.reverse()
# ランダムな価格データを生成
rand = np.random.default_rng().uniform
open = [100]
high = [100.02]
low = [100.02]
close = [100.05]
for i in range(n-1):
open.append(close[i])
close.append(open[-1] + rand(-0.1, 0.1))
high.append(max(open[-1],close[-1]) + rand(0, 0.05))
low.append(min(open[-1],close[-1]) - rand(0, 0.05))
# DataFrameに格納
ohlc_data = pd.DataFrame({
"date": dates,
"open": open,
"high": high,
"low": low,
"close": close
})
return ohlc_data.set_index("date", drop=True)
period_range = 50
df = generate_sample_ohlc_data(period_range)
df["signal"] = np.nan
print(df)
some_signal = mpf.make_addplot(df["signal"])
mpf.plot(df, type='candle', addplot=some_signal) # ValueError
Currently, we have worked around this by doing NaN pre-checking on the user side, but it would be great if the library could handle this.
issue case
When animating over a limited visual range, as in this example, the possibility arises that the signal columns are all NaN.
https://github.com/matplotlib/mplfinance/assets/37892107/a5afea85-57ce-4282-ad7c-955240c54787
issue
mplfinance\plotting.py", line 1108, in _addplot_columns ymhi = math.log(max(math.fabs(np.nanmax(yd)),1e-7),10) This Numpy code generates an error. "ValueError: zero-size array to reduction operation maximum which has no identity"
Error reproduction
Currently, we have worked around this by doing NaN pre-checking on the user side, but it would be great if the library could handle this.