Earlier, in the article [Python] Creating graphs that can be moved around with Plotly, I introduced a library called Plotly that can draw interactive graphs. However, I couldn't remember the spells I cast before drawing Plotly, and I copied and pasted from somewhere every time, so I always wondered if I could use it easily.
In such a situation, I found a library called Cufflinks that draws graphs using Plotly in one shot from a Pandas data frame, so I will introduce it.
Installation is complete with `pip install cufflinks`
.
To draw, just import Cufflinks and then type `df.iplot ()`
, just like `df.plot ()`
!
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(10, 2), columns=["col1", "col2"])
import cufflinks as cf
#By default, Plotly is in online mode, so change to offline mode
#How to permanently set the default to offline mode is described below
cf.go_offline()
df.iplot()
For detailed settings, refer to Tutorials on the Official Page. In addition, an example that seems to be used is shown below.
#Offline mode, white theme, link display OFF are default settings
cf.set_config_file(offline=True, theme="white", offline_show_link=False)
df.iplot(xTitle="X axis name", yTitle="Y axis name", title="title")
df.iplot(xrange=[0,5], yrange=[0,1])
df.iplot(kind="scatter" mode='markers', x="col1", y=["col2"]) #Series is specified by column name
subplot
df.iplot(subplots=True, shape=(2,1), shared_xaxes=True)
fig = df.figure(secondary_y="col2", yTitle="ylabel", xTitle="xlabel")
fig.layout.yaxis2.title = "y2label"
cf.iplot(fig)
Recommended Posts