画图神器:plot.ly

x轴整数序列

x轴时间序列

交互页面:https://plot.ly/~raywill/0/

做负载均衡的调优,需要把负载画出来看效果,使用了 plot.ly,实乃神器!
plot.ly 最大的特色是会把数据发到服务器,通过 web 完成渲染,形成可交互的图表。利用 plot.ly 写代码非常简单:

import MySQLdb
import plotly.plotly as py
from plotly.graph_objs import *
import pandas as pd



conn = MySQLdb.connect(host="127.0.0.1",port=3306,user="root", passwd="", db="oceanbase")
cursor = conn.cursor()

units = []

for unit_id in [1001, 1002, 1003, 1004, 1005, 1006]:
  cursor.execute('select gmt_create time, `load`, `disk_weight`, `disk_usage_rate` from __all_unit_load_history where unit_id = %d order by gmt_create limit 10000000' % (unit_id));
  rows = cursor.fetchall()
  df = pd.DataFrame( [[ij for ij in i] for i in rows] )
  df.rename(columns={0: 'time', 1: 'load', 2: 'disk_weight', 3: 'disk_usage_rate'}, inplace=True);
  unit0 = Scatter(
       x=df['time'],
       y=df['load'],
  )

  unit1 = Scatter(
      x = df['time'],
      y = df['disk_weight'],
  )

  unit2 = Scatter(
      x = df['time'],
      y = df['disk_usage_rate'],
  )
  units.append(unit0)

layout = Layout(
     xaxis=XAxis( title='time'),
     yaxis=YAxis( title='value', range=[0,1] )
)

data = Data(units)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='world')
print plot_url

note: 因为数据需要发往服务器,可以衍生出各种收费模式。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值