My First Matplotlib Project

Although it is a simple example, it is an instructive and repetitive project; shows the unemployment rate with covid 19. I just want to show.

If you want to see my project you can click;

https://github.com/cagataygulcan/covidunemployment/blob/master/Assignment4.ipynb

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import datetime
import numpy as np

First I added library in my notebook.

moons = ["year",1,2,3,4,5,6,7,8,9,10,11,12]
dff= pd.read_excel("SeriesReport-20200512120241_5969f4.xlsx",skiprows=15)
dff.columns=[moons]

a=dff.T
a.columns = ["2014","2015","2016","asd","2018","2019","2020"]
u=a.drop("year")

a=u["2020"].tolist()

Next, I uploaded unemployment rate from USA, and I edited.

unemploymoont=[]

for i in range(11):
    unemploymoont.append(a[0])
for i in range(29):
    unemploymoont.append(a[1])
for i in range(31):
    unemploymoont.append(a[2])
for i in range(30):
    unemploymoont.append(a[3])
    
dffmon = pd.DataFrame(unemploymoont)
dffmon.columns=["Urate"]

Then, I more edited unemployment rate data. I just divided months…

df = pd.read_csv("us_covid19_daily.csv")
df.columns

I uploaded United States covid data.

date=df["date"]
date=date.tolist()
dater = [str(i) for i in date]
year = [i[:4] for i in dater]
months = [i[4:6] for i in dater]
days= [i[6:] for i in dater]

Simple edits…

#positi= [str(i) for i in df["positive"]]
#positive= [i[:2]+"."+ i[2:] for i in positi if len(i)==7]
#positive2= [i[:3]+"."+ i[2:] for i in positi if len(i)==6]
#positive3= [i[:2]+"."+ i[2:] for i in positi if len(i)==5]
#positive4= [i for i in positi if len(i)==4]
#positive5= [i for i in positi if len(i)==3]
#positive6= [i for i in positi if len(i)==2 or len(i)==1]
#haspositive= [positive,positive2,positive3,positive4,positive5,positive6]

I had been started write to this code for decimal number, but later I noticed that I haven’t do that.

df["year"]=year
df["months"]=months
df["days"]=days

hasdata= df[["positive","negative","pending","year","months","days","death"]].sort_values(by="positive",ascending=True).reset_index()

So, same basic edits…

fig = plt.figure()
fig, ax = plt.subplots(1, 1)
datez = np.arange("2020-01-21","2020-05-11",dtype="datetime64[D]")

plt.plot(hasdata["positive"],lw=7, ls='-', marker='1')
ax.grid(True)


ax.set_ylabel(r"positive", fontsize=14, color="blue")

for label in ax.get_yticklabels():
    
    label.set_color("blue")




ax2 = ax.twinx()

ax2.plot(dffmon,color="red", lw=7, ls='--', marker='1')

ax2.set_ylabel(r"Unemployment  %", fontsize=14, color="red")

ax2.set_xticks([0, 30, 60, 90,120])



for label in ax2.get_yticklabels():
    
    label.set_color("red")



    


ax.set_title("Relation to Unemployment and Covid-19 in USA ");
ax.set_ylabel("Positive Cases of Covid-19")
ax.set_xlabel("Days Start Time: 2020-01-21*");
ax.legend(loc=4)
plt.legend(['Unemployment Rate', 'High Degrees', '2015 High Degrees',"2015 Low Degrees"])



fig.canvas.draw()

labels = [item.get_text() for item in ax.get_xticklabels()]
labels[0] = '21/01'
labels[1] = '21/02'
labels[2] = '21/03'
labels[3] = '21/04'

ax.set_xticklabels(labels)

label = [item.get_text() for item in ax.get_yticklabels()]
label[0]="0"
label[1]="0"
label[2]="200.000"
label[3]="400.000"
label[4]="600.000"
label[5]="800.000"
label[6]="1.000.000"
label[7]="1.200.000"
label[8]="1.400.000"


ax.set_yticklabels(label)


fig =plt.gcf()
fig.set_size_inches(18.5, 10.5)
plt.show()


fig.savefig('testjj.jpeg', dpi=100)

And finished.

My First Matplotlib Project

Leave a Reply

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

Scroll to top