Closed fivethreeo closed 6 months ago
Or just too large values in btc?
Possible that you can share the dataset where this happened? Does your timeseries have datetimes?
Only works with datetime strings
Was longs of ms data
Solved with:
df['date'] = pd.to_datetime(df['date'], unit='ms').dt.strftime('%Y-%m-%d')
Trying to plot all in javascript with pan and zoom, looks promising
So, no bug, just needs correct format, but datetime64 should maybe be supported?
My dataset has datetime series. I have converted them to datetime string as suggested.
Plotting does not work. I get the same error as posted by the op when I try to plot them. However printing pnf for single month data works fine. However multi month data run into issues. Can you pl help? Sample data attached.
Show some code.
Thanks for responding.
ret = finvasia_obj.get_time_price_series(exchange='NSE', token='26009',starttime=start_secs,endtime=end_secs, interval=1)
data = pd.DataFrame.from_dict(ret) data = data.sort_values(by='time') data.reset_index(drop=True, inplace=True)
data['time'] = pd.to_datetime(data['time'], format='%d-%m-%Y %H:%M:%S') data['time'] = data['time'].dt.strftime('%Y-%m-%d %H:%M:%S')
ts = data.rename(columns={'time':'datetime','into':'open','inth':'high','intl':'low','intc':'close'}).copy()
ts['open'] = ts['open'].astype(float).round(2) ts['high'] = ts['high'].astype(float).round(2) ts['low'] = ts['low'].astype(float).round(2) ts['close'] = ts['close'].astype(float).round(2)
ts = ts.to_dict('list')
pnf = PointFigureChart(ts=ts, method='h/l', reversal=3, boxsize=0.25, scaling='log', title='BANKNIFTY')
ts = data.rename(columns={'time':'date','into':'open','inth':'high','intl':'low','intc':'close'}).copy()
ts = data.rename(columns={'time':'date','into':'open','inth':'high','intl':'low','intc':'close'}).copy()
That worked! Thanks!
It plots fine. However with pnf.donchian(8,2) it raises a stack error
Cell In[11], line 51 46 # pnf.get_trendlines() 47 # print(pnf) 48 # pnf.get_trendlines(length=4, mode='weak') 49 # pnf.show_trendlines = 'external' 50 pnf.donchian(8,2) ---> 51 pnf.show() 53 # stack boxscale and matrix together and flip direction for readability in excel 54 pnf_matrix = np.flip(np.hstack((np.expand_dims(pnf.boxscale, axis=1),pnf.matrix)),0)
File ~/miniconda/envs/fyers/lib/python3.11/site-packages/pypnf/chart.py:2750, in PointFigureChart.show(self) 2747 def show(self): 2749 if self.fig is None: -> 2750 self._assemble_plot_chart() 2752 plt.show()
File ~/miniconda/envs/fyers/lib/python3.11/site-packages/pypnf/chart.py:2693, in PointFigureChart._assemble_plot_chart(self) 2692 def _assemble_plot_chart(self): -> 2693 self._prepare_variables_for_plotting() 2694 self._create_figure_and_axis() 2696 # plot grid
File ~/miniconda/envs/fyers/lib/python3.11/site-packages/pypnf/chart.py:2366, in PointFigureChart._prepare_variables_for_plotting(self) 2360 def _prepare_variables_for_plotting(self): 2361 """ 2362 Prepares matrix and indicator for plotting. Stores the cut_off_indices in attributes. 2363 The cut_off indices are needed to plot signals and trendlines 2364 """ -> 2366 self._indicator_plotting_preparations() 2368 if self.cut2indicator is True: 2369 self.plot_matrix = self.matrix[:, self.cut2indicator_length:]
File ~/miniconda/envs/fyers/lib/python3.11/site-packages/pypnf/chart.py:2200, in PointFigureChart._indicator_plotting_preparations(self) 2197 plot_indicator[key] = plot_indicator[key][indicator_cut_length:] 2199 if 'pSAR' not in key: -> 2200 plot_indicator[key] = self._coordinates2plot_grid(plot_indicator[key]) 2202 if 'pSAR' in key: 2203 sign = np.sign(plot_indicator[key])
File ~/miniconda/envs/fyers/lib/python3.11/site-packages/pypnf/chart.py:2140, in PointFigureChart._coordinates2plot_grid(self, array) 2137 scaling = self.scaling 2139 if scaling == 'log': -> 2140 base = 1 + pnf.boxsize / 100 2142 for num, val in enumerate(array): 2144 if not np.isnan(val):
NameError: name 'pnf' is not defined
That bug is fixed in dev. Install from github for now.
TypeError Traceback (most recent call last) Cell In[5], line 1 ----> 1 chart.show()
File /usr/src/app/resources/pnf.py:2781, in PointFigureChart.show(self) 2778 def show(self): 2780 if self.fig is None: -> 2781 self._assemble_plot_chart() 2783 plt.show()
File /usr/src/app/resources/pnf.py:2724, in PointFigureChart._assemble_plot_chart(self) 2723 def _assemble_plot_chart(self): -> 2724 self._prepare_variables_for_plotting() 2725 self._create_figure_and_axis() 2727 # plot grid
File /usr/src/app/resources/pnf.py:2447, in PointFigureChart._prepare_variables_for_plotting(self) 2444 self.plot_y_ticklabels = self.plot_boxscale[self.plot_y_ticks] 2446 # prepare x-ticks -> 2447 self.plot_column_label = self.column_labels[::-self.x_label_step] 2449 x_ticks = np.arange(np.size(self.column_labels)) 2450 self.plot_column_index = x_ticks[::-self.x_label_step] + 0.5
TypeError: 'NoneType' object is not subscriptable