如果你需要一個簡單、美觀、易用的可嵌入網頁的web可交互圖表(可放大縮小),并且可以保存為PNG、HTML,數據可導出CSV,那就是它了。
Pythonweb、GooPyCharts是對于谷歌圖表(Google Charts API)的python封裝。GooPyCharts的語法類似于MATLAB,實際上是對matplotlib庫的替代。
安裝 pip install gpcharts pip install future
Python圖表。第一張圖
三行就是一張簡單的圖:以默認的從0開始間隔1的x坐標畫出你給出的數組(plot函數里的列表),自動做擬合。
from gpcharts import figure
my_plot = figure(title='Demo')
my_plot.plot([1, 2, 10, 15, 12, 23])
運行后你的默認瀏覽器會打開并展示如下:
畫條形圖
我們畫出三個不同地區的氣溫-日期條形圖。日期自動轉換為Apr 1這種形式。
from gpcharts import figure
# 獲取圖像對象并設置x,y軸的值
fig3 = figure()
xVals = ['Temps','2016-03-20','2016-03-21','2016-03-25','2016-04-01']
yVals = [['Shakuras','Korhal','Aiur'],[10,30,40],[12,28,41],[15,34,38],[8,33,47]]
# 添加標題和Y軸標注,畫條形圖
fig3.title = 'Weather over Days'
fig3.ylabel = 'Dates'
fig3.bar(xVals, yVals)
畫散點圖
將上面的代碼稍作修改可以得到散點圖
from gpcharts import figure
#
my_fig = figure()
xVals = ['Dates','2016-03-20','2016-03-21','2016-03-25','2016-04-01'] # 第一個元素與上面不同
yVals = [['Shakuras','Korhal','Aiur'],[10,30,40],[12,28,41],[15,34,38],[8,33,47]]
#
my_fig.title = 'Scatter Plot'
my_fig.ylabel = 'Temps' # y軸標注做了修改
#
my_fig.scatter(xVals, yVals)
柱狀圖
很簡單的柱狀圖
from gpcharts import figure
#
my_fig = figure()
my_fig.title = 'Random Histrogram'
my_fig.xlabel = 'Random Values'
vals = [10, 40, 30, 50, 80, 100, 65]
my_fig.hist(vals)
其它
作者:treelake
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态