Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use matplotlib to draw K Diagram

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to use matplotlib to draw K diagram. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Apple stock data (2016-1-4-2017-4-20) are obtained in the following table:

DateOpenHighLowClose2016/1/4102.610001105.370003102105.3499982016/1/5105.75105.849998102.410004102.7099992016/1/6100.559998102.37000399.870003100.6999972016/1/798.68100.12999796.4396.4499972016/1/898.55000399.11000196.76000296.959999

Draw the code:

Import matplotlib.pyplot as pltfrom matplotlib.dates import DateFormatter, WeekdayLocator,DayLocator, MONDAYimport pandas as pdimport matplotlib.dates as mdatesfrom matplotlib.finance import candlestick_ohlc#1. Data preprocessing # read data data=pd.read_csv ("C:/Users/Administrator/Desktop/APPL/APPL.csv") # convert time data to pandas time format data ["Date"] = pd.to_datetime (data ["Date"]) # convert time data to matplotlib time format data ['Date'] = data [' Date'] .apply (lambda d: mdates.date2num (d.to_pydatetime () # transfer the data box Replace it with tuple tuples = [tuple (x) for x in data [['Date'] 'Open','High','Low','Close']] .values] # 2. Image setting # to get fig and ax object fig Ax = plt.subplots () # adjust the length of the Abscissa distance to the bottom fig.subplots_adjust (bottom=0.2) # set the display interval of Abscissa labels (display Monday of each week) mondays = WeekdayLocator (MONDAY) ax.xaxis.set_major_locator (mondays) # set the display interval of Abscissa ticks (each scale represents one day) alldays = DayLocator () ax.xaxis.set_minor_locator (alldays) # set the display style of Abscissa labels For "month, day", Jan 12weekFormatter = DateFormatter ('% b% d') ax.xaxis.set_major_formatter (weekFormatter) # shows the label # dayFormatter = DateFormatter ('% d') # ax.xaxis.set_minor_formatter (dayFormatter) # 3 for each scale. Drawing # Candlestick drawing candlestick_ohlc (ax, tuples, width=0.6,colorup='r',colordown= "g") # adjust the display style of the Abscissa label to obtain the current axis plt.gca, the x-axis scale label get_xticklabels, the conversion angle rotation, the rotation angle hori...entplt.setp (plt.gca (). Get_xticklabels (), rotation=45, horizontalalignment='right') plt.show ()

Result picture:

On "how to use matplotlib to draw K diagram" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report