I am trying to plot a python dictionary with {'file/path':number of files matching pattern}
. according to Plotting a python dict in order of key values this should work however I also realize that my x values are not an integer so this might be the case but I am not able to find an example where x axis is a string and y is number corresponding to it,
code
import os
import re
import numpy as np
import matplotlib.pyplot as plt
def find_pattern(root_dir,keyword):
out = {}
pattern = re.compile(keyword)
for filepath, subdirs, files in os.walk(root_dir):
for filename in files:
if pattern.match(filename):
if filepath not in out:
out[filepath] = 1
else:
out[filepath] = out[filepath] + 1
width = 1.0
print(out)
plt.bar(out.keys(), out.values(), width, color='g')
plt.show()
return out
find_pattern('/Users/vector8188/AlgorithmAnalysisPython', '^(.(?!.*\.css$|.*\.html))*$')`
content of out dictionary
`out = {'/Users/vector8188/AlgorithmAnalysisPython/.git/objects/28': 1, '/Users/vector8188/AlgorithmAnalysisPython/.git/objects/9a': 1, '/Users/vector8188/AlgorithmAnalysisPython/.git/objects/22': 1
}`
error:
Traceback (most recent call last):
File "apple_test.py", line 70, in <module>
find_pattern('/Users/vector8188/AlgorithmAnalysisPython', '^(.(?!.*\.css$|.*\.html))*$')
File "apple_test.py", line 66, in find_pattern
plt.bar(out.keys(), out.values(), width, color='g')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 2515, in bar
ret = ax.bar(left, height, width=width, bottom=bottom, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 5053, in bar
self.add_patch(r)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 1562, in add_patch
self._update_patch_limits(p)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 1580, in _update_patch_limits
xys = patch.get_patch_transform().transform(vertices)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/patches.py", line 576, in get_patch_transform
self._update_patch_transform()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/patches.py", line 569, in _update_patch_transform
bbox = transforms.Bbox.from_bounds(x, y, width, height)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/transforms.py", line 821, in from_bounds
return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
TypeError: cannot concatenate 'str' and 'float' objects