Fundamentals 7 min read

How to Visualize Kweichow Moutai Stock Data with Python and Matplotlib

This guide walks you through downloading Kweichow Moutai's historical stock data as a CSV file, handling encoding issues, and using Python's pandas and matplotlib libraries to create line charts of trading volume and OHLC prices for clear visual analysis.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Visualize Kweichow Moutai Stock Data with Python and Matplotlib

NetEase Finance provides a downloadable CSV file containing the historical trading data of Kweichow Moutai stock (see

). Clicking the “Download Data” link opens a dialog (see

), and the resulting file is in CSV format.

CSV (Comma‑Separated Values) is a plain‑text format used for data exchange between spreadsheets and databases. It can be opened with text editors like Notepad or with Excel, but be aware of encoding (GBK on Windows) and potential data loss when Excel auto‑converts values such as leading zeros.

Line Chart of Trading Volume

# coding=utf-8
# 代码文件:chapter6/ch6.2.6.py

import matplotlib.pyplot as plt
import pandas as pd

plt.rcParams['font.family'] = ['SimHei']    # 设置中文字体
plt.rcParams['axes.unicode_minus'] = False   # 设置负号正常显示

plt.figure(figsize=(15, 5))

f = r'data\股票的历史交易数据.xlsx'

df = pd.read_excel(f)

df2 = df.query("Date >='2021-03-01' and Date < '2021-04-01'").sort_values(by='Date')  # ①

# 绘制折线
plt.plot(df2['Date'], df2['Volume'])            # ②

plt.title('贵州茅台股票')
plt.ylabel('成交量')                      # 添加y轴标题
plt.xlabel('交易日期')                    # 添加x轴标题
plt.xticks(rotation=40)
plt.show()

Explanation:

Line ① filters the data for March 2021 and sorts it by date.

Line ② plots the trading volume against the date.

The resulting chart is shown below (see

).

OHLC Line Chart

# coding=utf-8
# 代码文件:chapter6/ch6.2.7.py

import matplotlib.pyplot as plt
import pandas as pd

plt.rcParams['font.family'] = ['SimHei']       # 设置中文字体
plt.rcParams['axes.unicode_minus'] = False    # 设置负号正常显示

plt.figure(figsize=(15, 5))

f = r'data\股票的历史交易数据.xlsx'

df = pd.read_excel(f)

df2 = df.query("Date >='2021-03-01' and Date < '2021-04-01'").sort_values(by='Date')

plt.title('贵州茅台股票历史OHLC折线图')
plt.plot(df2['Date'], df2['Open'], label='开盘价')     # ①
plt.plot(df2['Date'], df2['High'], label='最高价')
plt.plot(df2['Date'], df2['Low'], label='最低价')
plt.plot(df2['Date'], df2['Close'], label='收盘价')    # ②

plt.ylabel('成交量')
plt.xlabel('交易日期')
plt.xticks(rotation=40)
plt.show()

Explanation:

Lines ① and ② plot four line series for opening, highest, lowest, and closing prices, using the label parameter to identify each series in the legend.

The chart visualizing the OHLC data is displayed below (see

).

By following these steps, you can easily download, preprocess, and visualize a month’s worth of Moutai stock trading data, gaining clear insights into its price and volume trends.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data visualizationMatplotlibStock Data
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.