The main reason for plotting JSON data with Matplotlib is to make data more intuitive to understand and analyze.

  • Data visualization: Converting numeric JSON data into graphs makes it easier to identify trends and patterns.
  • Comparative analysis: You can quickly compare multiple values or variables at a glance.
  • Decision-making support: Visualizing data helps you grasp key insights faster and make informed decisions.
  • Reporting and presentation: Graphs make it easier to communicate data clearly and effectively.

In short, using Matplotlib to visualize JSON data enhances your ability to analyze and utilize data efficiently.

AALP Data, IBM Data, TSLA Data daily Data

Json Data to Matplot Code

import json
import matplotlib.pyplot as plt
import datetime

with open("b0043_IBM.json", "r") as fp_json:
    ibm_data = json.load(fp_json)

with open("b0043_AAPL.json", "r") as fp_json:
    aapl_data = json.load(fp_json)

with open("b0043_TSLA.json", "r") as fp_json:
    tsla_data = json.load(fp_json)

data_lsts = [[],[],[]]
open_lsts = [[],[],[]]
high_lsts = [[],[],[]]
low_lsts = [[],[],[]]
close_lsts = [[],[],[]]
volume_lsts = [[],[],[]]

tmp_datas = [ibm_data, aapl_data, tsla_data]
i = 0
for tmp_lsts in [ibm_data["Time Series (Daily)"],aapl_data["Time Series (Daily)"],
                           tsla_data["Time Series (Daily)"]]:
    for _date in tmp_lsts:
        tmp_data = tmp_lsts[_date]
        data_lsts[i%3].append(datetime.datetime.strptime(_date, '%Y-%m-%d'))
        open_lsts[i%3].append(float(tmp_data['open']))
        high_lsts[i%3].append(float(tmp_data['high']))
        low_lsts[i%3].append(float(tmp_data['low']))
        close_lsts[i%3].append(float(tmp_data['close']))
        volume_lsts[i%3].append(float(tmp_data['volume']))
    i+=1


plt.plot(data_lsts[0], open_lsts[0], 'b--', label="IBM")
plt.plot(data_lsts[1], open_lsts[1], 'r--', label="AAPL")
plt.plot(data_lsts[2], open_lsts[2], 'g--', label="TSLA")

plt.xlabel('Time')
plt.ylabel('Open')
plt.xticks(ticks=data_lsts[0], labels=data_lsts[0], rotation=25)
plt.locator_params(axis='x', nbins=10)
plt.legend()

plt.show()

I’ve plotted data for three companies—Apple, IBM, and Tesla—going back to 1999.

Apple appears to have had a stock split in the middle, followed by a steady rise.

IBM has remained relatively stable. It’s a bit disappointing since, with inflation, it could have seen more growth.

Tesla is tricky to analyze. Its sharp spikes sometimes distort the graph’s appearance. However, such extreme volatility is rare, making it crucial to track relevant news and map stock movements accordingly.

Either way, visualizing data like this allows for much faster analysis.

It’s estimated that we perceive 80–90% of information visually, and our brain processes images and graphs 60,000 times faster than text. That’s why visualization is such a powerful tool for analyzing any type of data.

By Mark

-_-

Leave a Reply

Your email address will not be published. Required fields are marked *