首页 > 编程知识 正文

R语言plotly,plotly用参数把数据存为HTML文件

时间:2023-05-03 12:47:14 阅读:172819 作者:4910

简单学习官方网站的例子

plotly官网

3359 github.com/tpof 314/plot ly _ examples

pip install-I https://pypi.tuna.Tsinghua.edu.cn/simpleplotlyimportplotlyplotly._ _ version _ _ importpandasasaspddddasasply plot ly _ examples-masterdataNZ _ weather.CSV ' ) data.head(importPort () importPort y=data['Auckland'] name=' Auckland ' ] fig=go.figure [ line1] fig.show (line1=go.scatter (x=data ) ) name=' Auckland ' line 2 nametzddb ) ) fig=go.fing line2]) ) fig.update _ layout (title=' new Zealand weather ',xaxis_title='Date ',date )

DATA_2010=data[(data(date ) ]=(2010-01 ) (data ) (date ) ) 2011-01 ) ] data _ 2010 bar1=go.bar text=datext text position=' outside ' ] fig=go.figure (bar1) fig.show ) bar1=go.bar text=data _ 2010 [ ' Auckland ' ],texx name=' Auckland ' ] bar2=go.bar (x=data _ 2010 [ text=data _ 2010 [ ' Wellington ' ] ',textposition='outside )

hist=go.histogram (x=data [ ' Auckland ' ] ) fig=go.figure ) hist ) fig.update_layout ) fig.show ) hist fig=go.figure(hist ) fig.update_layout ) bar xbins={ ' size ' :10 } (fig=go.figure (hist ) fig.update_layout ) bargap=0.1 ) (fig.show ) )。 importplotly.graph _ objectsasgoimportpandasaspddata=PD.read _ CSV (./data/iris.CSV ) (data.head ) ) point y=data['SepalWidth'],mode=' markers ' ] fig=go.figure (points ) fig.show ) importplotly.expressaspxfig=y

导入打印ly

.graph_objects as goimport pandas as pddata = pd.read_csv('C:\Users\Administrator\Desktop\plotly_examples-master\data\iris.csv')data.head() line = go.Scatter(x = data['x'], y = data['y'])fig = go.Figure(line)fig.show() line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'])fig = go.Figure(line)fig.show() line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'], mode='markers')fig = go.Figure(line)fig.show() line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'], mode='markers', marker={'size': 3, 'color': 'red'})fig = go.Figure(line)fig.show() plotly.express

import plotly.express as pxfig = px.scatter_3d(data, x='x', y='y', z='z', color='color')fig.show() import plotly.graph_objects as goimport pandas as pddata = pd.read_csv('C:\Users\Administrator\Desktop\plotly_examples-master\data\mt_bruno_elevation.csv')del data['index'] height = data.valuessurface = go.Surface(z = height)fig = go.Figure(surface)fig.show() import numpy as npx = np.arange(-5, 6)y = np.arange(-5, 6)xv, yv = np.meshgrid(x, y)xv'''array(传统的自行车, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]])'''yv'''array(传统的自行车, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5], [-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4], [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3], [-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2], [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]])'''z = xv**2 + yv**2z'''array([[50, 41, 34, 29, 26, 25, 26, 29, 34, 41, 50], [41, 32, 25, 20, 17, 16, 17, 20, 25, 32, 41], [34, 25, 18, 13, 10, 9, 10, 13, 18, 25, 34], [29, 20, 13, 8, 5, 4, 5, 8, 13, 20, 29], [26, 17, 10, 5, 2, 1, 2, 5, 10, 17, 26], [25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25], [26, 17, 10, 5, 2, 1, 2, 5, 10, 17, 26], [29, 20, 13, 8, 5, 4, 5, 8, 13, 20, 29], [34, 25, 18, 13, 10, 9, 10, 13, 18, 25, 34], [41, 32, 25, 20, 17, 16, 17, 20, 25, 32, 41], [50, 41, 34, 29, 26, 25, 26, 29, 34, 41, 50]])''' surface = go.Surface(x = xv, y = yv, z = z)fig = go.Figure(surface)fig.show() import plotly.graph_objects as goimport pandas as pddata = pd.read_csv('C:\Users\Administrator\Desktop\plotly_examples-master\data\earthquakes.csv')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")fig.show() import plotly.express as px# 准备数据df = px.data.gapminder().query("year == 2007").query("continent == 'Europe'")df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countriesdf.head() fig = px.pie(df, values='pop', names='country', title='Population of European continent')fig.show() import plotly.express as px# This dataframe has 244 lines, but 4 distinct values for `day`df = px.data.tips()df fig = px.pie(df, values='tip', names='day')fig.show() 设置还单身的戒指

import plotly.express as pxdf = px.data.tips()fig = px.pie(df, values='tip', names='day', color_discrete_sequence=px.colors.sequential.RdBu)fig.show() Sunburst charts

import plotly.graph_objects as gofig =go.Figure(go.Sunburst( labels=["懵懂的服饰", "ggdhb", "Seth", "Enos", "粗暴的帅哥, "愤怒的大地", "Awan", "淡定的煎饼", "Azura"], parents=["", "懵懂的服饰", "懵懂的服饰", "Seth", "Seth", "懵懂的服饰", "懵懂的服饰", "Awan", "懵懂的服饰" ], values=[10, 14, 12, 10, 2, 6, 6, 4, 4],))fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))fig.show() import plotly.express as pxdf = px.data.tips()fig = px.sunburst(df, path=['day', 'time', 'sex'], values='total_bill')fig.show()

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。