<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pandas DataFrame plotting with Highcharts
pandas_highcharts is a Python library to turn your pandas DataFrame into a suited JSON for Highcharts, a Javascript library for interactive charts.
Before introducing Highcharts, I build an arbitrary DataFrame with a timeseries (a Brownian motion), plot it with matplotlib, then seaborn and Highcharts.
Import
Step1:  Build a DataFrame with a timeseries
Step2:  Plotting with matplotlib
Step3:  Even if the figure is nicer than the matplotlib default style, I think it's to small, and legends don't fit when the number of variables is higher than 5 or 6.
Plotting with seaborn
Just a try with seaborn.
Step4:  The colors palette, the figure size and the legends position are OK for me.
Step5:  Let's go with Highcharts
Step6:  You can also retrieve the JSON data generated by pandas_highcharts thanks to the function serialize.
Step7:  Serialize the previous DataFrame with the pandas_highcharts function serialize.
Step9:  And display the charts thanks to the HTML renderer and the function display of IPython
Step10:  Try to change some parameters
You can also retrive the related Python dict before getting the JSON version. You'll have the same structure as Highcharts options and can change some parameters.
Step11:  Add a subtitle
Step12:  Change the chart type
Step14:  Serialize this new dict.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import string
import numpy as np
import pandas as pd
print pd.__version__
Explanation: Pandas DataFrame plotting with Highcharts
pandas_highcharts is a Python library to turn your pandas DataFrame into a suited JSON for Highcharts, a Javascript library for interactive charts.
Before introducing Highcharts, I build an arbitrary DataFrame with a timeseries (a Brownian motion), plot it with matplotlib, then seaborn and Highcharts.
Import
End of explanation
# Dimensions
nb_rand_var = 8
nb_dates = 220
np.random.seed(4321)
# Random choice letters
pickme = lambda x: np.random.choice(26, x, replace=False)
labels = np.array(list(string.ascii_uppercase))[pickme(nb_rand_var)]
labels
# Timeseries
ts = pd.date_range("2015-03-23", periods=nb_dates, freq="B")
ts
# A Brownian Motion
noise = np.random.randn(nb_dates, nb_rand_var)
df = pd.DataFrame(noise.cumsum(axis=0),
                  index=ts,
                  columns=labels)
df.head()
Explanation: Build a DataFrame with a timeseries
End of explanation
import matplotlib.pyplot as plt
plt.style.use("ggplot") # only for matplotlib >= 1.4
df.plot();
Explanation: Plotting with matplotlib
End of explanation
import seaborn as sns
with sns.axes_style("darkgrid"):
    df.plot()
Explanation: Even if the figure is nicer than the matplotlib default style, I think it's to small, and legends don't fit when the number of variables is higher than 5 or 6.
Plotting with seaborn
Just a try with seaborn.
End of explanation
with sns.axes_style("ticks"):
    df.plot()
Explanation: The colors palette, the figure size and the legends position are OK for me.
End of explanation
from pandas_highcharts.display import display_charts
display_charts(df, title="Brownian Motion")
Explanation: Let's go with Highcharts
End of explanation
from pandas_highcharts.core import serialize
Explanation: You can also retrieve the JSON data generated by pandas_highcharts thanks to the function serialize.
End of explanation
json_data = serialize(df, render_to="brownian", title="Brownian Motion")
type(json_data)
Explanation: Serialize the previous DataFrame with the pandas_highcharts function serialize.
End of explanation
from IPython.core.display import display, HTML
display(HTML(<div id="{chart_id}"</div>
<script type="text/javascript">{data}</script>.format(chart_id="brownian", data=json_data)))
Explanation: And display the charts thanks to the HTML renderer and the function display of IPython
End of explanation
data = serialize(df, render_to="brownian", output_type="dict")
data.keys()
data["chart"]
data["legend"]
Explanation: Try to change some parameters
You can also retrive the related Python dict before getting the JSON version. You'll have the same structure as Highcharts options and can change some parameters.
End of explanation
data["subtitle"] = {"text": "a subtitle here..."}
Explanation: Add a subtitle
End of explanation
data["chart"]["type"] = "spline"
data["plotOptions"] = {"spline": {
     "lineWidth": 2,
     "states": {
     "hover": {
     "lineWidth": 3}
     }}}
data['chart']['type'] = 'line'
data['chart']['zoomType'] = 'x'
data['chart']['panning'] = True
data['chart']['panKey'] = 'shift'
data["chart"]["renderTo"] = "new_brownian"
print data["chart"]
print data["subtitle"]
print data["yAxis"]
Explanation: Change the chart type
End of explanation
from pandas_highcharts.core import json_encode
json_data_2 = "new Highcharts.StockChart(%s);" % json_encode(data)
display(HTML(<div id="{chart_id}"</div>
<script type="text/javascript">{data}</script>.format(chart_id="new_brownian", data=json_data_2)))
Explanation: Serialize this new dict.
End of explanation
<END_TASK>