# How to retrieve the "counts" data as integers?

I'm trying to plot the counts for the same tensor state (00, say) over many runs, but I'm not sure how to access the data from the "counts" variable in a numerical format that is usable (with matplotlib, for example) after a given run. For context, the reason I am trying to do this is that each run corresponds to a Trotter timestep for unitary time evolution, and I'm trying to plot the evolution of the 00 state over time to compare with the numerical result.

Any help is appreciated!

• can you provide example code?
– poig
Commented Jun 23, 2022 at 2:00
• results.get_counts() returns a dictionary where each key represents a resulting state (eg. 00, 01..) and the values are the total counts for that state. Do you mean that you're trying to extract the result per run (eg. run0 => 00, run1 => 00 run2 => 11)? Commented Jun 23, 2022 at 7:33
• @Iftachyakar Embarrassingly, I'm a Python novice and had no knowledge of the dictionary datatype. Thank you very much for your comment. Commented Jun 23, 2022 at 13:44
• @Robert I recommend you to use dir() and qiskit documentation, to see what attribute is available, and play with them. There is other more scenario of retrieve counts data, when you talk about trotter timestep.
– poig
Commented Jun 23, 2022 at 15:23
• Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
– Community Bot
Commented Jun 23, 2022 at 18:23

If counts is shown something like {'0': 1, '1': 14}, then to retreive the count for say 1 as 14as cnt_value_1 = counts.get('1') so that the count value is stored in variable cnt_value_1.