1

My dataset is a simple one:

Product volume by month

I'm using python hvplot to draw subplots by simply giving a "col" statement"

    bar = df.hvplot.bar('month', 'volume', col = 'product', \
height = 200, width = 200, rot=90, logy = True, grid = True)

The plot looks like this:

sample plot

I want to hide the plot title area (dashline circled part) or move it to the bottom of plot. I searched the internet, but didn't find much clue. Appreciate if someone can help me out.

A side question, how do I specify bar fill color by product name? hvplot doesn't seems to support cmap.

doppler
  • 997
  • 5
  • 17

2 Answers2

1

First, welcome to Stackoverflow! For the future, please provide a so-called MWE: https://stackoverflow.com/help/minimal-reproducible-example

Short answer:

df.hvplot.bar('x', 'y', row='z').opts(xaxis=False)

will remove what you call the "title".

Long answer:

hvplot returns Holoviews objects, see

import holoviews as hv

Some (if not most) customization options can only be accessed directly through Holoviews itself. In this case, since your provided the col parameter, it gives you a holoviews GridSpace, see here:http://holoviews.org/reference/containers/matplotlib/GridSpace.html

so what you call the "subplots title" is actually the axis of your GridSpace! And this is what you switch off using the xaxis=False call.

You can get inline help on available options via

hv.help(hv.GridSpace)
doppler
  • 997
  • 5
  • 17
0

There are many ways to move the product labels down in your barplot:

# import libraries
import pandas as pd
import holoviews as hv
import hvplot
import hvplot.pandas

# create example dataframe 
df = pd.DataFrame({
    'product': ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'],
    'month': ['201801', '201802', '201803', '201801', '201802', '201803',  '201801', '201802', '201803'],
    'volume': [100, 125, 110, 85, 87, 96, 177, 167, 130]
})

Possible solutions:

# create barplot option 1
df.hvplot.bar(x=['product', 'month'], y='volume')

# or do it like this
df.hvplot.bar(x='product', y='volume', by='month')

# or create your barplot like this
hv.Dataset(df).to.bars(['product', 'month'], 'volume')

This will result in the following plot: barplot labels down

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96