0

Setting plotly as a backend for pandas, you can produce plots quickly and easily using:

df.plot()

enter image description here

How can you make this setup produce other plots than lineplots? And what other options are there?

1 Answer 1

3

You can define which plot type you'd like to produce through the kind argument in:

df.plot(kind='line')

kind='line' produces the very same plot as in the question. Valid options are:

['scatter', 'line', 'area', 'bar',
 'barh', 'hist', 'box', 'violin',
 'strip', 'funnel', 'density_heatmap',
 'density_contour', 'imshow']

You can easily study them all by running:

for k in kinds[:-1]:
    df.plot(kind=k).show()

Plots:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Notice that I've used kinds[:-1]. This is because imshow is for image data and requires a dataset a bit more complicated than [1,2,3,4,5,6]. Please refer to this and Plotting an image with imshow from a pandas dataframe

In order to set the titles and title colors for all other options, here's a complete code snippet:

import random
import pandas as pd

random.seed(123)
df = pd.DataFrame({'x':[1,2,3,4,5,6]})
pd.options.plotting.backend = "plotly"

kinds = ['scatter', 'line', 'area', 'bar', 'barh', 'hist', 'box', 'violin', 'strip', 'funnel', 'density_heatmap', 'density_contour', 'imshow']

for k in kinds[:-1]:
    fig = df.plot(kind=k, title = k)
    fig.update_layout(title = dict(font=dict(color='#EF553B')))
    fig.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.