Issue
I've the below code which is giving me 141 rows. While trying to plot them in matplotlib bar graph, it's throwing error. But when the same code is giving me 3 rows, it's plotting them successfully. The code is:
import os
import cx_Oracle
import matplotlib.pyplot as plt
import numpy as np
dsn_tns = cx_Oracle.makedsn('host', '1521', service_name='S1')
conn = cx_Oracle.connect(user=r'dev_user', password='Welcome', dsn=dsn_tns)
reportid_count = []
count_ID = []
c = conn.cursor()
query = 'select distinct (LTRIM(REGEXP_SUBSTR(ID, '[0-9]{3,}'), '0')) as ReportID,count(ID) from dev_user.RECORD_TABLE group by ID'
c.execute(query)
#loop through the rows fetched and store the records as arrays.
for row in c:
reportid_count.append(row[0])
print(row[0])
count_ID.append(row[1])
print(row[1])
fig = plt.figure(figsize=(13.5, 5))
#plot the bar chart
plt.barh(reportid_count,count_ID)#,color=['red', 'blue', 'purple']
for i, v in enumerate(count_ID):
plt.text(v, i, str(v), color='blue', fontweight='bold')
plt.title('Report_Details')
plt.xlabel('Report Count')
plt.ylabel("Report ID's")
path = r"\\dev_server.com\View\Foldert\uidDocuments\Store_Img"
os.chdir(path)
plt.savefig(path + '\squares.png')
plt.show()
conn.close())
The error is:
Traceback (most recent call last): File "\dev_server.com\View\Foldert\uid\POC\Daily_Reporting_POC\BAR_Report.py", in plt.barh(report_count,agent_id) #,color=['red', 'blue', 'purple'] File "\dev_server.com\View\Foldert\uid\Docs\Conda_Env\Env_Poc\lib\site-packages\matplotlib\pyplot.py", line 2503, in barh y, width, height=height, left=left, align=align, **kwargs) File "\dev_server.com\View\Foldert\uid\Docs\Conda_Env\Env_Poc\lib\site-packages\matplotlib\axes_axes.py", line 2631, in barh align=align, **kwargs) File "\dev_server.com\View\Foldert\uid\Docs\Conda_Env\Env_Poc\lib\site-packages\matplotlib_init_.py", line 1447, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "\dev_server.com\View\Foldert\uid\Docs\Conda_Env\Env_Poc\lib\site-packages\matplotlib\axes_axes.py", line 2486, in bar label='nolegend', File "\dev_server.com\View\Foldert\uid\Docs\Conda_Env\Env_Poc\lib\site-packages\matplotlib\patches.py", line 750, in init self._x1 = self._x0 + self._width TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' PS Microsoft.PowerShell.Core\FileSystem::\dev_server.com\View\Foldert\uid\Docs\DashBoard_POC\Daily_Report_POC>
Solution
Check what's the second list returning...whether it contains any None type data or not. It seems during the addition it's failing.
Answered By - Cris-123
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.