来自python中json属性的Matplotlib

我正在尝试将此json文件属性转换为matplotlib,其中图中的x“显示关注者数量”和y“具有特定关注者数量的用户的频率”。

这是我的json文件的样子

[{"user": "person1","follower": 1008,"following": 2520},{"user": "person2","follower": 144,"person3": 394},{"user": "person4","follower": 483,"following": 1582},...]

我已经将json文件导入到python中,但是我无法弄清楚如何使用特定属性在matplotlib(不是熊猫图)中绘制图

import pandas as pd
import json
instagram = json.loads(open('J:\\data.json').read())
df = pd.DataFrame(instagram)
print (df)
df.plot(x='user',y='follower')
wcnm2132 回答:来自python中json属性的Matplotlib

您可以使用:

import matplotlib.pyplot as plt
plt.scatter(df['x'],df['y'])
plt.show()
,

在这里,您可以在x轴上显示关注者,并在y轴上显示关注者数量的用户频率

import pandas as pd
import matplotlib.pyplot as plt

# if you are running in jupyter notebook - uncomment the below line
# %matplotlib inline

d = [{"user": "person1","follower": 1008,"following": 2520},\
     {"user": "person6",\
     {"user": "person7",\
     {"user": "person3","following": 123},\
     {"user": "person2","follower": 144,"following": 394},\
     {"user": "person5","following": 987},\
     {"user": "person4","follower": 483,"following": 1582}]

df = pd.DataFrame(d)
dfg = df.groupby('follower').count()

# using matplotlib scatter chart
plt.scatter(x=dfg.index,y=dfg['user'])
plt.show()

# using pandas plot
dfg.plot()
本文链接:https://www.f2er.com/3164259.html

大家都在问