Python: Matplotlib – How to use csv and subplots for beginners

So how do I use subplots?


from matplotlib.pyplot import  *
import numpy as np, os
from typing import List
#get file 
def get_file(filename: str):
	#determines validity of path 
	#returns file content 
	filepath = os.path.abspath(filename)
	if os.path.exists(filepath):
		fh = open(filepath)
		header = fh.readline() #excludes first row of the csv file e.g. x,y
		data = {"x":[],"y":[]}
		for row in fh.readlines():
			if len(row) <= 0: break print(len(row)) row = row.rstrip() x,y = row.split(",") x,y = float(x), float(y) data["x"].append(x) data["y"].append(y) fh.close() return data return False #plot the data -> subplots ( arguments in function)
def get_plot(data: List):
	#first create a figure --> a space where your subplots will be drawn into 
	fig = figure()
	x,y  = data["x"], data["y"]
	#create the first subplot x,y 
	plot(x, y)
	bar(x, y)
	hist(x, np.arange(1, len(x)))

def task(filename):
	data = get_file(filename)
	if data:
		return get_plot(data)
	return False 


When I run the file, the following figure is generated:

#I know, it does not scream “pretty data visualization” but the code works I guesss.. See ya!

error: Content is protected !!