Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Put zero for x axis values
#1
Hello,
I have this dict:

od = OrderedDict([(0, 1), (1, 1), (3, 1), (7, 1), (36, 1)])
And I am plotting this array with the following line:
plt.bar(range(len(od)), list(od.values()), align='center')
plt.xticks(range(len(od)), list(od.keys()),rotation='vertical')
IN this example for x axis, I have 0,1,3,7,36. However I don't have 2 between 1 and 3 and I don't have any other numbers between 7 and 36. So I want to update my dict like that:
od=([(0, 1), (1, 1),(2,0), (3, 1), (7, 1), (8,0),(9,0),(10,0),(11,0),...(36, 1)])
How can I do that?

I tried this way:
finalarray=np.zeros(60) # or sth larger than max (input dict keys)
for k,v in  od: 
    print(k,v)
    finalarray[k]=v
And I got this error:
Error:
TypeError: cannot unpack non-iterable int object
Reply


Messages In This Thread
Put zero for x axis values - by quest - Jul-28-2021, 11:03 PM
RE: Put zero for x axis values - by Larz60+ - Jul-29-2021, 01:59 AM
RE: Put zero for x axis values - by quest - Jul-29-2021, 09:49 AM
RE: Put zero for x axis values - by quest - Jul-29-2021, 01:32 PM
RE: Put zero for x axis values - by DeaD_EyE - Jul-29-2021, 01:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print names in x-axis of a time-series values hobbyist 4 1,218 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  Getting proper x,y axis values pyhill00 8 1,638 Jul-29-2022, 06:48 PM
Last Post: pyhill00
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,116 May-17-2022, 11:38 AM
Last Post: Larz60+
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,339 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,468 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123
  Sort y axis by descening values matplotlib mrsenorchuck 0 3,797 Dec-08-2019, 08:13 PM
Last Post: mrsenorchuck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020