最近在**院实习,需要撰写土地全生命周期的年报,今年多期的数据需要可视化。以前的图片样式太过普通,领导想要一些样式精美的图表,无意发现了python的plotly库,可以绘制十分精美的图表。
学习资源:
1、官网在这里
2、plotly绘图说明,这篇博客讲解十分详细
3、本文参考这篇文章(可视化神器–Plotly)
安装plotly
#win7控制台安装
pip install plotly --user
使用
导入库文件
import plotly
import plotly.graph_objs as go
import numpy as np
import plotly.offline as py
1. 绘制折线图
n=100
rand_x = np.linspace(0,1,n)
rand_y1 = np.random.randn(n)+5
rand_y2 = np.random.randn(n)
rand_y3 = np.random.randn(n)-5
trace1 = go.Scatter(
x = rand_x,
y = rand_y1,
mode = 'markers',
name = 'markers'
)
trace2 = go.Scatter(
x = rand_x,
y = rand_y2,
mode = 'lines+markers',
name = 'lines+markers'
)
trace3 = go.Scatter(
x = rand_x,
y = rand_y3,
mode = 'lines',
name = 'lines'
)
data = [trace1,trace2,trace3]
py.iplot(data)
#
2. 绘制散点图
散点图同1,如下:
trace_markers = go.scatter(
y = np.random