python - Add x and y labels to a pandas plot -


suppose have following code plots simple using pandas:

import pandas pd values = [[1,2], [2,5]] df2 = pd.dataframe(values, columns=['type a', 'type b'], index=['index 1','index 2']) df2.plot(lw=2,colormap='jet',marker='.',markersize=10,title='video streaming dropout category') 

output

how set x , y-labels while preserving ability use specific colormaps? noticed plot() wrapper pandas dataframes doesn't take parameters specific that.

the df.plot() function returns matplotlib.axes.axessubplot object. can set labels on object.

in [4]: ax = df2.plot(lw=2,colormap='jet',marker='.',markersize=10,title='video streaming dropout category')  in [6]: ax.set_xlabel("x label") out[6]: <matplotlib.text.text @ 0x10e0af2d0>  in [7]: ax.set_ylabel("y label") out[7]: <matplotlib.text.text @ 0x10e0ba1d0> 

enter image description here

or, more succinctly: ax.set(xlabel="x label", ylabel="y label").

alternatively, index x-axis label automatically set index name, if has one. df2.index.name = 'x label' work too.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -