python - Plot a pandas dataframe with vertical lines -


i want plot dataframe each data point not represented point vertical line 0 axis :

df['a'].plot(style='xxx')

where xxx style need.

also ideally able color each bar based on values in column in dataframe.

i precise x axis values numbers , not equally spaced.

the pandas plotting tools convenient wrappers matplotlib. there no way know of functionality want directly via pandas.

you can in few lines of matplotlib. of code colour mapping:

import pandas pd import matplotlib.pyplot plt import numpy np import matplotlib.colors colors import matplotlib.cm cmx  #make dataframe = np.random.rand(100)     b = np.random.ranf(100)     df = pd.dataframe({'a': a, 'b': b})  # colour mapping c_norm  = colors.normalize(vmin=min(df.b), vmax=max(df.b)) scalar_map = cmx.scalarmappable(norm=c_norm, cmap=plt.get_cmap('jet'))     color_vals = [scalar_map.to_rgba(val) val in df.b]  # make plot plt.vlines(df.index, np.zeros_like(df.a), df.a, colors=color_vals) 

i've used dataframe index x axis values there no reason not use irregularly spaced x values.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -