In: Computer Science
Use python 2.7 & plotly (dash) to draw bar/line graph for below data
OrderedDict([('0K', 7.239253544865276), ('PK', 3.236322216916338), ('1', 6.415793586505012), ('2', 6.020145027564326), ('3', 5.658685936530415), ('4', 5.37435274038192), ('5', 5.1860079887723085), ('6', 5.035941053040876), ('7', 5.1264549715408), ('8', 5.553318856838249), ('9', 12.200551540951867), ('10', 11.195203964258715), ('11', 8.990680759944928), ('12', 12.767287811888968)])
Make sure all keys, especially the 0K & PK, are showing in the x-axis.
Here is the code to do so:
if the answer helped you please upvote and if you have any doubts please comment i will surely help. please take care of the indentation while copying the code. Check from the screenshots provided.
Code:
from collections import OrderedDict
import matplotlib.pyplot as plt
data = OrderedDict([('0K', 7.239253544865276), ('PK', 3.236322216916338), ('1', 6.415793586505012), ('2', 6.020145027564326), ('3', 5.658685936530415), ('4', 5.37435274038192), ('5', 5.1860079887723085), ('6', 5.035941053040876), ('7', 5.1264549715408), ('8', 5.553318856838249), ('9', 12.200551540951867), ('10', 11.195203964258715), ('11', 8.990680759944928), ('12', 12.767287811888968)])
plt.plot(data.keys(), data.values())
plt.show()