Python 3 Matplotlib & Pandas Script to Plot JSON DataFrames as Interactive Charts as PNG Images
423 views
Jun 1, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you a Python
0:04
script which will actually plot a
0:07
colorful u charts using uh some JSON
0:12
data that you will provide so as you can
0:14
see inside this Python script we have a
0:17
raw JSON data which contains three
0:19
properties here uh the name age and city
0:24
so we have three rows of data right here
0:27
so if I want to plot this a simple bar
0:31
chart we can use a library called as
0:34
mattplot lip so if I just execute this
0:37
script here it actually plots the data
0:40
right here inside this data
0:42
visualization graphs or chart you may
0:44
call this and on the x-axis we have the
0:47
names on the y-axis we have the ages so
0:51
in this easy
0:52
way you can plot the data and the nice
0:55
thing is that we also have the button to
0:57
save this into a image file so as soon
1:00
as you click the save button you can
1:02
save this data into a image file so as
1:06
soon as you do this you can see your
1:08
graph is successfully saved as a PNG
1:10
image file so this is a bar chart but
1:14
you can actually plot any sort of chart
1:18
this library that I showed you is uh
1:20
Matt plot lip so first of all you just
1:23
need to install
1:26
this so it's a data visualization
1:29
plotting package from raw data you can
1:32
plot various kinds of charts bar chart
1:35
pie chart line chart scatter chart so
1:38
this is the documentation so the command
1:40
is simple you simply say pip install
1:43
mattplot lip apart from that you also
1:46
need to install this pandas library
1:48
which is a data visualization package as
1:51
well so this package is also required so
1:55
now let me show you a very simple
1:57
example so how to get started with this
2:01
library so first of all you need to
2:04
import both the packages like
2:07
this mattplot lib
2:13
after importing it you'll be declaring
2:16
this JSON data which will contain a
2:18
array of JSON object each object contain
2:22
three properties
2:24
here name age and city so you can take
2:27
any sort of data that you want to
2:30
plot this data can be coming from an API
2:33
as well or database after that this JSON
2:36
data we need to convert this into pandas
2:39
data frame so we simply say PD dot dataf
2:47
frame so this PD package like this so
2:52
this
2:57
is data
2:59
frame and you simply pass the JSON data
3:03
after
3:04
that this will actually convert
3:08
your data JSON data to data
3:12
frame you can print this so this looks
3:15
something like
3:17
this let me just stop this application
3:19
and again run this this will convert
3:22
this JSON data to this pandas data frame
3:27
so using this it becomes easy for you to
3:30
plot this data into a it contains this
3:33
plot
3:35
function and here you need to specify
3:37
which kind of chart so I will say bar
3:40
chart you will see we have all the
3:42
options pie chart as
3:46
well so then you need to provide on the
3:50
x-axis the value name on the
3:54
y-axis which will be the ages and the
3:58
title of the chart will be
4:01
age
4:05
report so we are basically on the x-axis
4:08
on the horizontal axis names will be
4:10
displayed on the y-axis vertical axis
4:13
ages will be displayed so this is
4:16
essentially the bar chart and then to
4:18
plot this we have this function of
4:20
mattplot
4:24
lip on the y-axis we have the ages and
4:28
then to show the chart here we have the
4:30
show method so this will instantly show
4:34
the chart to us as soon as we run the
4:36
application so if I run this you will
4:38
see your bar chart will be displayed in
4:42
a different window
4:44
you can visually see the actual data
4:46
that you
4:48
have so now let's suppose if I change
4:50
this data just make it
4:56
90 again run
4:59
this you can see as soon as I change
5:01
this data the bar graph will also change
5:06
so in this easy way you can actually
5:08
plot this data visualization from just
5:12
JSON
5:13
data very simply using pandas and
5:17
mattplot liib library uh also check out
5:20
my website which is freemediatools.com
5:23
uh which contains uh thousands of tools
#Programming
#Scripting Languages
#Software