Python | Plotting using Dictionary

In this tutorial, we are going to learn how to plot data which is stored in a dictionary?
Submitted by Anuj Singh, on August 06, 2020

Sometimes, data is available in the format of a Dictionary and we can use it directly to plot in matplotlib without converting it into separate lists.

The following example is an illustration of how to plot using Dictionary.

Illustration:

Python | Plotting using Dictionary

Python code for plotting using dictionary

import numpy as np
import matplotlib.pyplot as plt

data = {'a': np.arange(50),
        'c': np.random.randint(45, 50, 50),
        'd': np.random.randint(40,45,50)}

plt.plot('a', 'c', data=data)
plt.bar('a', 'd', data=data)
plt.ylim(20,55)
plt.xlabel('entry a')
plt.ylabel('entry c')
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.