I created a candlestick chart using matplotlib.pyplot in python3.
An error has occurred when trying to add a moving average line to the same image.
fig = plt.figure (figsize = (8, 12), face color ='# 101010') ax1 = fig.add_subplot (211, face color ='#cccccc') ax2 = fig.add_subplot (212, facecolor ='# bbbbbb') ax1.set_title ('chart:'+ pair, color ='# 000000') ax1.grid () ax2.set_title ('RSI', color ='# 000000') ax2.grid () mpf.candlestick2_ochl (ax1, opens = hist1min ['oMid'], closes = hist1min ['cMid'], highs = hist1min ['hMid'], lows = hist1min ['lMid'], width = 0.5, color up ='k ', colordown ='r', alpha = 0.75) ax1.plot (hist1min.index, hist1min ['up2000']) ## error ## ax1.plot (hist1min.index, hist1min ['cMid']. Rolling (4) .mean ()) ax1.set_xticklabels ([(hist1min.index [int (x)]. strftime ("% H:% M") if x<hist1min.shape  else x) for x in ax1.get_xticks ()], rotation = 30) ax2.set_xticklabels ([(hist1min.index [int (x)]. strftime ("% H:% M") if x<hist1min.shape  else x) for x in ax2.get_xticks ()], rotation = 30) bottom, top = ax1.get_ylim () ax1.set_ylim (bottom-(top --bottom)/4, top) ax1b = ax1.twinx () volume_overlay (ax1b, hist1min ['oMid'], hist1min ['cMid'], hist1min ['tickqty'], width = 0.5, colorup = "g", colordown = "g") ax1b.set_ylim ([0, hist1min ['tickqty']. max () * 4]) ax1b.set_ylabel ('volume') with plt.style.context ('grayscale'): plt.savefig ('zzz_graph.png', transparent = False) plt.close ()
If i do not enter the commented out part with the above ## error ##, you can make a graph, but if you execute the commented part, the following error will occur.
Traceback (most recent call last): File "05_gazo.py", line 463, in<module> getLast (cnt) File "05_gazo.py", line 243, in getLast ax1.set_xticklabels ([(hist1min.index [int (x)]. strftime ("% H:% M") if x<hist1min.shape  else x) for x in ax1.get_xticks ()], rotation = 30) File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 3191, in get_xticks return self.xaxis.get_ticklocs (minor = minor) File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/axis.py", line 1329, in get_ticklocs return self.major.locator () File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1249, in __call__ self.refresh () File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1269, in refresh dmin, dmax = self.viewlim_to_dt () File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1026, in viewlim_to_dt .format (vmin)) ValueError: view limit minimum -36854.15829861111 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
I made it with reference to the following site, but I can't find a workaround.
Sorry to trouble you, but if you can understand the solution, I would appreciate it if you could teach me.
Answer # 1
I was able to respond with the following.
Is it because there is no value for 20 in bb calculation?
ax1.plot (range (len (hist1min)), hist1min ['up2000'], color = "# ff00ff")
ax1.plot (range (len (hist1min)), hist1min ['dn2000'], color = "# ff00ff")
- matplotlib - i'm trying to display a diagram, but i get an error and can't display it
- python - i want to display the correlation coefficient on the matplotlib graph
- python - even if i try to display the waveform display of audio data with matplotlib, the dimensions of (x, y) do not match beca
- python - when trying to compress a file in a folder with a zip file with the file name acquired by oswalk, if there are subfolde
- display images by drag and drop on wxpython gui
- file gets corrupted when trying to edit a pdf file in python
- how to scrape in python and display in a browser?
- python - matplotlib i want to draw a horizontal line
- i want to get the value from a constant in python and display it
- python - i want to display an image with pysimplegui, but an error occurs
- python 3x - display a specific string in a text file
- excel python i want to get the display result instead of the conditional statement
- python - i want to display the scraping result in the browser
- i want to display images periodically in python, what should i do?
- python - about x-axis adjustment in matplotlib
- python - i want to display the maximum and minimum values from the n real numbers i entered
- i want to display annotations in order with matplotlib
- python - image display from the variable to which the file name is assigned
- python - about image display and position of main ()
- [python] unable to use packages installed with wsl
- python - i want to display a graph of matplotlib on tkinter and enable mouse operation in canvas
- about python animation axis setting
- matplotlib - how to plot the same day of the week in another year
- matplotlib - i want to draw a stacked bar graph
- matplotlib - i want to draw a 3d scatter plot
- matplotlib - embedding in python tkinter doesn't work and update fails
- matplotlib - where to save the animation video
- python - i want to find the average hsv value for each divided image
- matplotlib - the image of matplot is displayed on the gui of tkinter, but i want to display the histogram in a separate window