0
아래 예제의 nvd3 선형 차트는 python list를 데이터 소스로 사용합니다. 그러나 판다 플롯에서와 같이 명시 적으로 열을 명시하지 않고 팬더 데이터 프레임에서 여러 줄을 그릴 방법은 df.plot()
df에 x
열을 포함 할 수 있습니다. nvd3을 사용하는 데이터 프레임의 다중 선 차트
from nvd3 import lineChart
# Open File for test
output_file = open('test_lineChart.html', 'w')
# ---------------------------------------
type = "lineChart"
chart = lineChart(name=type, x_is_date=False, x_axis_format="AM_PM")
xdata = list(range(0, 24))
ydata = [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 3, 3, 5, 7, 5, 3, 16, 6, 9, 15, 4, 12]
ydata2 = [9, 8, 11, 8, 3, 7, 10, 8, 6, 6, 9, 6, 5, 4, 3, 10, 0, 6, 3, 1, 0, 0, 0, 1]
kwargs1 = {'color': 'black'}
kwargs2 = {'color': 'red'}
extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}}
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie, **kwargs1)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(y=ydata2, x=xdata, name='cose', extra=extra_serie, **kwargs2)
chart.buildhtml()
output_file.write(chart.htmlcontent)
# close Html file
output_file.close()
어떻게 nvd3 사용하여이 dataframe에서 플롯하려면 다음과 같이
list
에
index
및
column
데이터를 변환해야하므로
df = pd.DataFrame(data)
df = df.set_index('datetime')
fig, ax = plt.subplots()
df.plot(ax=ax, marker='o')