首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在python中绘制和显示数据集的分布?

如何在python中绘制和显示数据集的分布?
EN

Stack Overflow用户
提问于 2021-05-04 12:25:20
回答 1查看 21关注 0票数 0

我有一个数据集,其中的一小部分如下所示,

代码语言:javascript
复制
data = [ ['2018-01-01',  1.323 ,    'AI' ,   2000,'Communications','Mothers'], 
   ['2018-01-02',  1.525 ,    'AI',    1500,'Communications','Mothers'],
   ['2018-01-03',  1.045 ,    'AI' ,    500,'Communications','Mothers'],
   ['2018-01-04',  1.845 ,    'AI' ,    600,'Communications','Mothers'],
  ['2018-01-05',  1.045 ,    'AI' ,    500,'Communications','Mothers'],
   ['2018-01-02',  1.446  ,  'BOC' ,    550,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-03',  2.110 ,   'BOC' ,   3201,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-04',  2.150 ,   'BOC' ,   5200,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-05',  2.810 ,   'BOC' ,   1980,'Pharmaceuticals','JASDAQ Standard'],
   ['2018-01-03',  5.199 ,   'CAT' ,   2000,'Real Estate','Mothers'],
  ['2018-01-06',  4.980 ,   'CAT' ,    450,'Real Estate','Mothers'],
  ['2018-01-07',  4.990 ,   'CAT' ,   3000,'Real Estate','Mothers']]
df = pd.DataFrame(data,columns =['date',  'price', 'ticker',  'volume', 'Sector','Market Division'])

我想要显示哪个市场部门有更多的库存,来自哪个部门。我尝试了下面的树状地图,但没有工作,我怎么做呢?

代码语言:javascript
复制
import plotly.express as px
import numpy as np

a=df.groupby(['Market Division','Sector']).count()

a["Exchange"] = "Exchange" # in order to have a single root node
fig = px.treemap(a, path=['Exchange', 'Market Division', 'Sector','ticker'], values='ticker')
fig.show()
EN

回答 1

Stack Overflow用户

发布于 2021-05-04 12:56:10

您可以尝试使用stacked plots。下面是一个虚拟示例:

代码语言:javascript
复制
import matplotlib.pyplot as plt
labels = list(set([md for md in df['Market Division']]))
fig, ax = plt.subplots()
jasdaq = [3434, 5454, 45454] 
mothers = [35345, 64534, 43543]
ax.bar(labels, jasdaq[0], label='Pharmaceuticals')
ax.bar(labels, jasdaq[1], label='Communication')
ax.bar(labels, jasdaq[2], label='Real Estate')
ax.bar(labels, mothers[0], label='Pharmaceuticals')
ax.bar(labels, mothers[1], label='Communication')
ax.bar(labels, mothers[2], label='Real Estate')

ax.legend()
plt.show()

您需要首先计算每个Market分区的每个扇区,并替换jasdaq和mothers,以获得您想要的真实图。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67378790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档