当前位置: 首页 > news >正文

绍兴的网站建设公司/优化方案电子版

绍兴的网站建设公司,优化方案电子版,疫情最新消息今天新增多少例,甘肃省人民政府最新任免大佬看到这里就可以走了, 小白可以继续看了,本篇文章只是【plotly】入门级 注意:本篇文章使用的是离线版本的plotly,没有用线上版的,直接在pycharm上运行的。 入门篇 plotly安装 plotly导入plotly模块example1 Scatter…

大佬看到这里就可以走了, 小白可以继续看了,本篇文章只是【plotly】入门级

注意:本篇文章使用的是离线版本的plotly,没有用线上版的,直接在pycharm上运行的。

入门篇 plotly

      • 安装 `plotly`
      • 导入`plotly`模块
      • example1 `Scatter`
      • example2 `Bar`
      • example3 `Histogram`
      • example4 `Express`
      • example5 `pie`
      • example6 `3D`
      • example7 `Densitymapbox`
      • `plotly`官方文档:

安装 plotly

pip install plotly

导入plotly模块

import plotly.graph_objects as go 
import plotly.offline as of  	# 这个为离线模式的导入方法
import pandas as pd #使用pandas处理csv数据

example1 Scatter

通过Scatter方法画折线图:

data = pd.read_csv(r'C:\Users\Administrator\Desktop\data\nz_weather.csv')
print(data.head()) #显示5条数据
# Scatter
line1 = go.Scatter(y=data['Auckland'], x=data['DATE'], name='Auckland')   # name定义每条线的名称
line2 = go.Scatter(y=data['Wellington'], x=data['DATE'], name='Wellington')
fig = go.Figure([line1, line2])
fig.update_layout(title = 'New Zealand Weather', #定义生成的plot 的标题xaxis_title = 'DATE',		#定义x坐标名称yaxis_title = 'Weather'		#定义y坐标名称
)
of.plot(fig)
使用数据:DATE  Auckland  Christchurch Dunedin Hamilton  Wellington
0  2000-01     115.4          47.2   174.8     96.2        91.8
1  2000-02       8.4          25.2      41      8.2        35.2
2  2000-03      57.2          60.8    74.2     33.8        53.4
3  2000-04     106.8          58.2      50    129.6       109.8
4  2000-05     128.2          62.0      '-     98.2        78.2

在这里插入图片描述

example2 Bar

通过Bar画条形图:

# Bar  
# 由于数据有很多,我就挑选一年的数据做为示例
data_2010 = data[(data['DATE'] >= '2010-01') & (data['DATE'] < '2011-01')] 
bar1 = go.Bar(y=data_2010['Auckland'], x=data_2010['DATE'],text = data_2010['Auckland'], textposition = 'outside', name='Auckland') # 
bar2 = go.Bar(y=data_2010['Wellington'], x=data_2010['DATE'],text = data_2010['Wellington'], textposition = 'outside', name='Wellington') # textpositon 是将text数据显示在条形柱上, outside是外面, inside是里面 ;name 和上述Scatter一样
fig = go.Figure([bar1,bar2])
fig.update_layout(title = 'New Zealand Weather',xaxis_title = 'DATE',yaxis_title = 'Weather',
)
of.plot(fig)

在这里插入图片描述
注解图:
在这里插入图片描述

example3 Histogram

Histogram统计某列数据的次数:

# Histogram
hist1 = go.Histogram(x=data['Auckland'], xbins={'size': 10}, name='Auckland') # xbins={'size': 10} 是以10为范围,统计数据次数
hist2 = go.Histogram(x=data['Wellington'], xbins={'size': 10}, name='Wellington')
fig = go.Figure([hist1, hist2])
fig.update_layout(title = 'New Zealand Weather',xaxis_title = 'Weather',yaxis_title = 'count',bargap = 0.1, # 是柱与柱之间存在空隙
)
of.plot(fig)

在这里插入图片描述

example4 Express

Express 是一种更方便的制作图表的方法:

  • 导入Express
    import plotly.express as px
  • 使用Express 来完成example1的方法:
# plotly.express
import plotly.express as px
data = pd.read_csv(r'C:\Users\Administrator\Desktop\data\iris.csv')
fig = px.scatter(data, x='SepalLength', y='SepalWidth',color='Name',)  
of.plot(fig)
使用的数据:鸢尾花数据集SepalLength  SepalWidth  PetalLength  PetalWidth         Name
0          5.1         3.5          1.4         0.2  Iris-setosa
1          4.9         3.0          1.4         0.2  Iris-setosa
2          4.7         3.2          1.3         0.2  Iris-setosa
3          4.6         3.1          1.5         0.2  Iris-setosa
4          5.0         3.6          1.4         0.2  Iris-setosa

在这里插入图片描述

example5 pie

通过Express方法生成饼图:

data = pd.read_csv(r'C:\Users\Administrator\Desktop\data\pie-charts-with-excel.csv')
print(data.head())
fig = px.pie(data, names=data['Label'], values=data['Values'], title='pie-charts-with-excel',)
of.plot(fig)
使用数据:Unnamed: 0   Label  Values
0           0  ZDS.FY      70
1           1  RPF.JV      20
2           2  ACC.UM      17
3           3  NCY.LC      76
4           4  EIK.JE      99

在这里插入图片描述

example6 3D

  • 普通方法生成3D plot
# 3D
data1 = pd.read_csv(r'C:\Users\Administrator\Desktop\data\3d-line1.csv')
#print(data1.head())
line1 = go.Scatter3d(x=data1['x'], y=data1['y'], z=data1['z'],mode='markers', marker={'size': 3, 'color': data1['color']})
fig4 = go.Figure(line1)
of.plot(fig4)
  • Express方法生成3D plot
fig5 = px.scatter_3d(data1, x='x', y='y', z='z', color='color')
of.plot(fig5)
使用数据:x         y         z  color
0  100.000000  0.613222  0.734706      0
1   99.238875  0.589852  0.781320      0
2   99.559608  0.599743  0.762566      0
3   97.931425  0.549296  0.859966      0
4   96.837832  0.515613  0.927150      0

在这里插入图片描述

example7 Densitymapbox

生成地图数据:

data = pd.read_csv(r'C:\Users\Administrator\Desktop\data\earthquakes.csv')
# print(data.head())
my_map = go.Densitymapbox(lat=data['Latitude'], lon=data['Longitude'], z=data['Magnitude'], radius=4)
fig = go.Figure(my_map)
fig.update_layout(mapbox_style='open-street-map')  #必须有这个地图参数#可以使用的免费地图:"open-street-map", "carto-positron", "carto-darkmatter", "stamen-terrain", "stamen-toner" or "stamen-watercolor"
of.plot(fig)
使用数据:Date  Latitude  Longitude  Magnitude
0  01/02/1965    19.246    145.616        6.0
1  01/04/1965     1.863    127.352        5.8
2  01/05/1965   -20.579   -173.972        6.2
3  01/08/1965   -59.076    -23.557        5.8
4  01/09/1965    11.938    126.427        5.8

在这里插入图片描述

plotly官方文档:

https://plotly.com/python/


结束语:
1.所有的数据都可以在plotly官方的github上找到。
2.如果我有什么讲得不好的地方欢迎大佬指点评论
3.原文链接https://blog.csdn.net/weixin_43347550/article/details/106163458

http://www.jmfq.cn/news/4966093.html

相关文章:

  • wordpress mac客户端/seo怎么做新手入门
  • 个人虚拟网站/怎么弄一个网站平台
  • 重庆网站设计哪家公司好/seo sem优化
  • githup网站建设/百度广告服务商
  • 05网/优化关键词排名的工具
  • 用wordpress做的网站/国际军事形势最新消息
  • 源代码网站怎么建设/百度网络小说排行榜
  • 站群系统软件/百度站长平台网站收录
  • wordpress主题首页问题/抖音seo怎么收费
  • dede 网站被复制/上海网站关键词排名优化报价
  • 要如何做才能拥有自己的网站呢/新型实体企业100强
  • 做网站的宣传语/刷关键词指数
  • 有没有做外贸免费网站/友链通
  • 青云 wordpress加速/常州seo外包
  • 安阳网站建设哪家正规/站长工具查询系统
  • 怎么才可以做网站/如何做seo搜索优化
  • 苏州网页制作服务/seo薪资seo
  • 书生商友软件下载/seo搜索是什么
  • 网站建设宣传单设计模板/长沙网络公关公司
  • cms网站制作/网站点击率查询
  • 建设商城网站制作/seo公司彼亿营销
  • 深圳做网站三网合一/win优化大师怎么样
  • 建设部网站查询/个人博客网站模板
  • 网站建设怎么报印花税/策划是做什么的
  • 超链接网站怎么做/张家港seo建站
  • h5可以制作公司网站吗/国内能用的搜索引擎
  • 视频宣传片制作拍摄/晨阳seo顾问
  • 炫酷业务网站/南宁seo结算
  • 建设网站费用多少钱/企业品牌推广方案
  • 河南公司网站建设/视频号推广