matplotlib questions
Steve
Gronicus at SGA.Ninja
Fri Aug 27 23:39:05 EDT 2021
I would like to know how the data is placed on the Y-axis and at the tops of
the bars.
The data is not being shown properly. With some exceptions, it looks as if
the data is getting sorted independently from the dates.
OK, here is the code:
==============================================
# https://matplotlib.org/stable/gallery/index.html
import matplotlib.pyplot as plt
import numpy as np
width = 12 #Width of the graph
height = 6 #Height of the graph
plt.rcParams["figure.figsize"] = (width,height)
plt.rcParams["font.size"] = (9.0)
Count = 0
datesList = [] # Each date showing end of bottle use
hoursList = [] # Number of hours
# daysList = [] # Number of days calculated from hours/24
countList = [] # simple tally
with open("__Insulin_Tracker.txt", 'r') as infile:
for lineEQN in infile:
insulinHours = lineEQN[47:52].strip()
print("Hours = " + insulinHours)
hoursList.append(insulinHours)
insulinDates = lineEQN[20:30].strip()
datesList.append(insulinDates)
# insulinDays= lineEQN[57:62].strip()
# daysList.append(insulinDays)
Count += 1
countList.append(str(Count))
# print(" " + str(Count) + " " + insulinDates + " Hours: " +
insulinHours)
x = Count
count = str(Count)
# Each date indicated the date on which a bottle of insulin has been
depleted
# The bar is to show the number of hours that the bottle has been in use.
Labels = datesList
Xdata= hoursList
Title = ("Bottle List Number of entries: " + count)
x = np.arange(len(Labels)) # the label locations
width = 0.35 # the width of the bars
margin = 0
fig, ax = plt.subplots()
fig.tight_layout(pad=10) # Sets the size of the graph
rects1 = ax.bar(x - width/2, Xdata, width, label='Hours') #Populates the x
axis
# Add some text for labels, title and custom x-axis tick labels, etc.
# fontsize = 20
ax.set_ylabel('Hours of use for each bottle')
ax.set_title(Title)
ax.set_xticks(x)
ax.set_xticklabels((datesList), rotation = 90) #Dates at bottom of the graph
ax.legend()
ax.bar_label(rects1, padding=0,rotation = 90)
plt.show()
===================================
Here is my data in __Insulin_Tracker.txt (with indents)
===================================
Sat Jan 02, 2021 15 29 1.21
Thu Jan 07, 2021 01 116 4.83
Tue Jan 12, 2021 01 120 5.00
Fri Jan 15, 2021 23 74 3.08
Tue Jan 19, 2021 22 95 3.96
Fri Jan 22, 2021 21 71 2.96
Tue Jan 26, 2021 08 103 4.29
Sun Jan 31, 2021 23 115 4.79
Fri Feb 05, 2021 01 118 4.92
Mon Feb 08, 2021 20 71 2.96
Thu Feb 11, 2021 18 80 3.33
Tue Feb 16, 2021 08 120 5.00
Fri Feb 19, 2021 18 72 3.00
Wed Feb 24, 2021 01 113 4.71
Sun Feb 28, 2021 22 97 4.04
Thu Mar 04, 2021 11 95 3.96
Mon Mar 08, 2021 18 103 4.29
Sat Mar 13, 2021 15 117 4.88
Wed Mar 17, 2021 10 91 3.79
Sun Mar 21, 2021 00 96 4.00
Fri Mar 26, 2021 00 120 5.00
Tue Mar 30, 2021 17 103 4.29
Sat Apr 03, 2021 00 89 3.71
Wed Apr 07, 2021 23 99 4.12
Sun Apr 11, 2021 05 98 4.08
Thu Apr 15, 2021 14 95 3.96
Sun Apr 18, 2021 23 71 2.96
Fri Apr 23, 2021 23 120 5.00
Tue Apr 27, 2021 17 100 4.17
Tue Jul 27, 2021 21 2178 90.75
Sun Aug 01, 2021 18 127 5.29
Thu Aug 05, 2021 23 91 3.79
Tue Aug 10, 2021 17 124 5.17
Sat Aug 14, 2021 21 90 3.75
Thu Aug 19, 2021 09 128 5.33
Wed Aug 25, 2021 02 137 5.71
-----Original Message-----
From: Python-list <python-list-bounces+gronicus=sga.ninja at python.org> On
Behalf Of David Lowry-Duda
Sent: Friday, August 27, 2021 3:25 PM
To: python-list at python.org
Subject: Re: matplotlib questions
> I am trying to modify the "Bar Graph Demo" at
> https://matplotlib.org/stable/gallery/index.html, Lines, bars, and
> markers but the more I experiment and change the code, the more messed
> up it becomes.
It is much easier to give constructive suggestions if you give a minimum
runnable code sample that indicates what you're trying and what you're
trying to do. See also http://catb.org/~esr/faqs/smart-questions.html
I'll also note that I see nothing called "bar graph demo" on the gallery
page.
- DLD
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list