'Plotly change figure size by calling cufflinks in pandas

I am trying to change the figure size (height and width) of the figure that I called using plotly cufflinks for pandas. I know that I could separately Layout from plotly.graph_objs and then give the height and width command. However, is there a way I could control the font and/or figure parameters using cufflinks.

I am plotting the Reasons for delisting of stocks on X axis and their count on Y.

Here is my code

grped = d_list_data.groupby(['Reasons Short']).size()
import cufflinks as cf
grped.iplot(kind = 'bar', 
        xTitle = 'Reasons for Delisting', 
        yTitle= 'Count', 
        title= 'Delisting Reasons since 2001', 
        theme = 'polar',
        )


Solution 1:[1]

Define a Layout with your desired height and width properties and use it inside the cufflinks iplot call.

layout1 = cf.Layout(
    height=300,
    width=200
)
grped.iplot(kind = 'bar', 
        xTitle = 'Reasons for Delisting', 
        yTitle= 'Count', 
        title= 'Delisting Reasons since 2001', 
        theme = 'polar',
        layout=layout1
        )

Solution 2:[2]

I tried this within Jupyterlab and using the above approach was getting error: AttributeError: 'Layout' object has no attribute 'get'

Converting the layout to a dict as suggested here (https://community.plot.ly/t/cant-edit-layouts-with-cufflinks/15038/4) made it work.

So, the above becomes:

layout1 = cf.Layout(
    height=300,
    width=200
)
grped.iplot(kind = 'bar', 
        xTitle = 'Reasons for Delisting', 
        yTitle= 'Count', 
        title= 'Delisting Reasons since 2001', 
        theme = 'polar',
        layout=layout1.to_plotly_json()
        )

Solution 3:[3]

The iplot method has the following parameter that controls the dimension of the chart: dimensions : tuple(width,height). So you could try:

grped.iplot(kind = 'bar', 
    xTitle = 'Reasons for Delisting', 
    yTitle= 'Count', 
    title= 'Delisting Reasons since 2001', 
    theme = 'polar',
    dimensions =(300,200)
    )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexandre Ackermans
Solution 2 Rockgecko
Solution 3 RonG