1

I have dictionary as:

    ```{'0.0': 2.445616223564293,
       '0.05': 2.445594095119315,
       '0.1': 2.4455740588234223,
       '0.15': 2.4455560866270947,
       '0.2': 2.4455401509059596,
       '0.25': 2.4455262244535803,
       '1.0': 2.4455411399961293,
       '1.05': 2.44555597697399,
        '1.1': 2.4455724183134344,
       '1.15': 2.4455904432448716,
       '1.2': 2.445610031303073,
        '1.25': 2.4456311623222002,
       '2.0': 2.4461204322901566,
       '3.0': 2.447205696789686,
       '4.0': 2.4486856713473726,
        '5.0': 2.4504762863004363,
        '10.0': 2.4623061878090624,
        '20.0': 2.4922549001247876}```

Here all the values are different by some small factor. However when I plot it using matplotlib the plot is not distinctive.

I want to plot "keys" in x-axis and "values" in y-axis and then find x which has minimum y value by looking the plot.

I tried this code:

       ```plt.plot(*zip(*data))```

But the plot is not clear. How can I solve this problem such that plot is clearly able to show the difference in values.

1 Answer 1

1

The problem is your interpretation of zip(*data). I would suggest before plotting you first print and see what you are trying to plot.

print (list(zip(*data))) would print a list of splitted strings (keys of your data). To plot the keys on the x-axis and the values of the y-axis, simply do the following. I leave the visualization of the minimum up to you. If you want to plot the difference, subtract the first value from the complete list of values and then plot it on the y-axis.

plt.plot(data.keys(), data.values(), '-bx')
plt.xticks(rotation=45)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

It's still not proper. If you see, the line is flat from 0.0 to 1.2. But in reality there is difference among the values. And also minimum is at 0.25
@MAC : Add the following line at the end plt.ylim(2.445, 2.446) and you will see the plot is correct with its minima at 0.25. The values are so close so of course it is hard to see the minimum without restricting the y-axis range

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.