I have created a program that gets data and creates 2 lists:
1) Date_list - which contains dates.
2) Data - which contains some data.
At the moment, it plots the date_list in the x axis and the data in the y axis. But my graph is for some reason connecting the start and end points with an additional line. I would like to disable that... How can I do it?
The image below shows my issue.
Here's my code:
from notion.client import NotionClient
from datetime import datetime
from matplotlib import pyplot as plt
import matplotlib.dates as mdates
import numpy
import pandas as pd
# Obtain the `token_v2` value by inspecting your browser cookies on a logged-in session on Notion.so
client = NotionClient(token_v2="")
# Replace this URL with the URL of the page you want to edit
page = client.get_collection_view("")
all_rows = list(page.build_query().execute())
all_rows_data = [row.get_all_properties() for row in all_rows]
date_list = []
data = []
# Add the data of the dates and the respective screen time into 2 separate lists.
for item in all_rows_data:
date_time = item.get('title') + ' 2020'
screen_time = item.get('screen_time')
datetime_object = datetime.strptime(date_time, '%d %B %Y')
#print(datetime_object, screen_time)
date_list.append(datetime_object)
data.append(screen_time)
# Plot a graph using Matplotlib
ax = plt.gca() #get axes
formatter = mdates.DateFormatter("%d %B %Y") #format as a date
ax.xaxis.set_major_formatter(formatter)
locator = mdates.DayLocator() #set locator
ax.xaxis.set_major_locator(locator)
fig = plt.figure(figsize=(15, 5)) # Plot graph
ax = fig.add_subplot(111)
ax.plot(date_list, data, color='red', marker='o', markerfacecolor='blue', markersize=8)
ax.plot()
plt.show()
Any code suggestions are welcome too!
Thanks in advance,
Karthik