Skip to content

Instantly share code, notes, and snippets.

View ConanMercer5's full-sized avatar

Conan Mercer ConanMercer5

View GitHub Profile
import pandas as pd #pandas library that supports reading a comma-separated values (csv) file into DataFrame
df = pd.read_csv('https://covid.ourworldindata.org/data/owid-covid-data.csv') #df stands for DataFrame
import matplotlib.pyplot as plt
import numpy as np
from cycler import cycler # Used to add color cycle using colors from a colormap
plt.title('Percentage of 4 components', bbox={'facecolor':'0.8', 'pad':5}, loc='left') # Adds a title and its postion
labels = ['Component 1', 'Component 2', 'Component 3', 'Component 4']
sizes = [17, 35, 24, 31]
colors = plt.cm.gray(np.linspace(0.2,0.8,5)) # Adds a grey scale
import matplotlib.pyplot as plt
plt.title('Percentage of 4 components', bbox={'facecolor':'0.8', 'pad':5}, loc='left') # Adds a title and its postion
labels = ['Component 1', 'Component 2', 'Component 3', 'Component 4']
sizes = [17, 35, 24, 31]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'red', 'blue']
plt.pie(sizes, colors = colors, labels=labels, autopct='%1.1f%%', startangle=90, pctdistance=0.85) # Adds a title and postions it
centre_circle = plt.Circle((0,0),0.70,fc='white') # draws a circle
@ConanMercer5
ConanMercer5 / PieChart1.py
Last active July 6, 2020 15:47
Python code for the most basic Pie Chart
import matplotlib.pyplot as plt
labels = ['Component 1', 'Component 2', 'Component 3', 'Component 4'] # adds labels to each component
sizes = [17, 35, 24, 31] # an array giving the values assigned to each component
explode = (0, 0, 0.1, 0) # this "explodes" the 3rd slice of the Pie
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
@ConanMercer5
ConanMercer5 / JSON
Created May 10, 2020 13:56
JSON format used for ThingSpeak
{"write_api_key":"WRITE_API_KEY",
"updates":[{"delta_t":"TIME_STAMP","field1":"FIELD1_VALUE","field2":"FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE"},
{"delta_t":"TIME_STAMP","field1":"FIELD1_VALUE","field2":"FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE"},
{"delta_t":"TIME_STAMP","field1":"FIELD1_VALUE","field2":"FIELD2_VALUE","field3":"FIELD3_VALUE","field4":"FIELD4_VALUE"}]}
@ConanMercer5
ConanMercer5 / BulkUpdate.ino
Created May 1, 2020 11:03
Bulk Update to ThingSpeak
#include<EthernetClient.h> // Library to work with ESP-12E board, used to connect to a specified internet IP address and port
#include<ESP8266WiFi.h> // Library to work with ESP-12E board
#include <SPI.h> // Library to work with Serial Peripheral Interface (SPI) serial data
#include <Wire.h> // Library to communicate with I2C devices
#include <Adafruit_MLX90614.h> // Library to communicate with IR sensors
#include "SSD1306.h" // Library to work with SSD1306 LOED display
#define SDA 5 // Serial data line on pin D5
#define SCL 4 // Serial clock line on pin D4
SSD1306 display(0x3c, SDA, SCL); // Initialise the OLED display using Wire library