python - Bubble plot or Heatmap in matplotlib -
i trying plot dynamically size able bubble (scatter map). when try plot random data can plot. when trying parse input file not able plot.
input:
nos,place,way,name,00:00:00,12:00:00 123,london,air,apollo,342,972 123,london,rail,beta,2352,342 123,paris,bus,beta,545,353 345,paris,bus,rava,652,974 345,rome,bus,rava,2325,56 345,london,air,rava,2532,9853 567,paris,air,apollo,545,544 567,rome,rail,apollo,5454,5 876,japan,rail,apollo,644,54 876,japan,bus,beta,45,57
program:
import pandas pd pandas import dataframe import pandas.io.data import matplotlib.pyplot plt import numpy np import seaborn sns df=pd.read_csv('text_2.csv') #size of bubbles changes fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.scatter(df['place'],df['name'], s=df['00:00:00']) # added third variable income size of bubble plt.show()
i trying put place
x axis
, name
y axis
, size
taken count(00:00)
. sizable bubble not find of examples around. valuable suggestions appropriated. in advance. why error @ (00:00) column , how pass values of column ?
error:
traceback (most recent call last): file "bubble_plot.py", line 18, in <module> ax.scatter(df['place'],df['name'], s=df['00:00:00']) # added third variable income size of bubble file "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6266, in scatter x, y, s, c = cbook.delete_masked_points(x, y, s, c) file "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 1774, in delete_masked_points raise valueerror("first argument must sequence") valueerror: first argument must sequence
i hoping might work changing 'name' , 'place' categoricals, no luck there (with either plot or seaborn). work if convert them integers lose labels you'd have strings or categoricals. fwiw:
df2 = df.copy() c in ['place','name']: df2[c] = df2[c].astype('category').cat.codes fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.scatter(df2['place'],df2['name'], s=df2['00:00:00'])
or maybe heatmap work better? seems accept categoricals, labeling free.
df3 = df.copy() c in ['place','name']: df3[c] = df3[c].astype('category') sns.heatmap( df3.pivot_table( index='place', columns='name', values='00:00:00' ) )
Comments
Post a Comment