[Python] Plotly draws Pandas dataframes in one shot with Cufflinks

Introduction

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.

Installing and using Cufflinks

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()

newplot.png

Fine settings

For detailed settings, refer to Tutorials on the Official Page. In addition, an example that seems to be used is shown below.

Change default settings

#Offline mode, white theme, link display OFF are default settings
cf.set_config_file(offline=True, theme="white", offline_show_link=False)

Designation of title and initial display area

df.iplot(xTitle="X axis name", yTitle="Y axis name", title="title")
df.iplot(xrange=[0,5], yrange=[0,1])

Scatter plot

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)

2nd Y-axis plot

fig = df.figure(secondary_y="col2", yTitle="ylabel", xTitle="xlabel")
fig.layout.yaxis2.title = "y2label"
cf.iplot(fig)

Recommended Posts

[Python] Plotly draws Pandas dataframes in one shot with Cufflinks
Automatically generate frequency distribution table in one shot with Python
How to calculate "xx time" in one shot with Python timedelta
One liner webServer (with CGI) in python
One liner in Python
Scraping with selenium in Python
[In one line] Visualize like a lawn with just Pandas
Scraping with chromedriver in python
Debugging with pdb in Python
DMD in Python one dimension
Working with sounds in Python
Scraping with Selenium in Python
[Python] Change dtype with pandas
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
How to create dataframes and mess with elements in pandas
Swap columns in pandas dataframes
[Python3] Save the mean and covariance matrix in json with pandas
How to display legend marks in one with Python 2D plot
Number recognition in images with Python
Make python segfault in one line
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Scraping with Selenium in Python (Basic)
Draw knots interactively in Plotly (Python)
CSS parsing with cssutils in Python
Numer0n with items made in Python
Open UTF-8 with BOM in Python
How to convert 0.5 to 1056964608 in one shot
Use rospy with virtualenv in Python3
[Python] Join two tables with pandas
Dynamically create new dataframes with pandas
Use Python in pyenv with NeoVim
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
Use OpenCV with Python 3 in Window
Until dealing with python in Atom
Get started with Python in Blender
Working with DICOM images in Python
Excel aggregation with Python pandas Part 1
[Python] Format when to_csv with pandas
Reading from text files and SQLite in Python (+ Pandas), R, Julia (+ DataFrames)
Join data with main key (required) and subkey (optional) in Python pandas
Create "operation log" CSV formatting tool in 5 days with Python Pandas PyInstaller
Handle multiple python versions in one jupyter
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
CGI server (1) python edition in one line
Stress Test with Locust written in Python
Python3> in keyword> True with partial match?
Device monitoring with On-box Python in IOS-XE
Try working with binary data in Python
Draw Nozomi Sasaki in Excel with python
Tips for dealing with binaries in Python
Display Python 3 in the browser with MAMP
Page cache in Python + Flask with Flask-Caching
Post Test 3 (Working with PosgreSQL in Python)