Py之mpld3:mpld3的簡(jiǎn)介、安裝、使用方法之詳細(xì)攻略
? ? ? ?mpld3——Bringing Matplotlib to the Browser?.? ?mpld3 是matplotlib 和 javascript D3js 得到的可以在網(wǎng)頁(yè)上繪圖的工具。mpld3基于python的graphing library和D3js,匯集了Matplotlib流行的項(xiàng)目的Java庫(kù),用于創(chuàng)建web交互式數(shù)據(jù)可視化。通過(guò)一個(gè)簡(jiǎn)單的API,將matplotlib圖形導(dǎo)出為HTML代碼,這些HTML代碼可以在瀏覽器內(nèi)使用。
?? ? ?mpld3項(xiàng)目匯集了流行的基于Python的圖形庫(kù)MaPutTLIB和D3JS,這是用于創(chuàng)建Web交互式數(shù)據(jù)可視化的流行JavaScript庫(kù)。結(jié)果是一個(gè)簡(jiǎn)單的API,用于將MatMattLIB圖形導(dǎo)出到HTML代碼中,這些代碼可以在瀏覽器內(nèi)使用,在標(biāo)準(zhǔn)網(wǎng)頁(yè)、博客或工具如iPython筆記本中使用。
mpld3
mpld pypi
?
pip install mpld3
輸出結(jié)果
實(shí)現(xiàn)代碼
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import mpld3
from mpld3 import plugins
np.random.seed(9615)
# generate df
N = 100
df = pd.DataFrame((.1 * (np.random.random((N, 5)) - .5)).cumsum(0),
columns=['a', 'b', 'c', 'd', 'e'],)
# plot line + confidence interval
fig, ax = plt.subplots()
ax.grid(True, alpha=0.3)
for key, val in df.iteritems():
l, = ax.plot(val.index, val.values, label=key)
ax.fill_between(val.index,
val.values * .5, val.values * 1.5,
color=l.get_color(), alpha=.4)
# define interactive legend
handles, labels = ax.get_legend_handles_labels() # return lines and labels
interactive_legend = plugins.InteractiveLegendPlugin(zip(handles,
ax.collections),
labels,
alpha_unsel=0.5,
alpha_over=1.5,
start_visible=True)
plugins.connect(fig, interactive_legend)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Interactive legend', size=20)
mpld3.show()
相關(guān)文章推薦
mpld3 Example
聯(lián)系客服