简体   繁体   中英

Bubble Plot Pandas (or Python) Weekday/Hour of day

I'm trying to generate a Bubble plot that plots a frequency to Weekday and the hour of day, exactly like this plot: https://i.stack.imgur.com/TP4ZF.jpg The data is in a pandas dataframe of the following format:

weekday hour freq
    0   0    22710
    0   1    22685
    0   2    21673
    0   3    22276
    0   4    21531
    0  ...    ...
    0   23   12343
   ...  ...   ...
    6   23   34231

I tried the following, but it didn't work at all:

df.plot.scatter(x='hour', y='weekday', s=df['freq']);

The generated graph seems to have the right axes but is covered in one large blue rectangle (see https://i.stack.imgur.com/2BLzR.png ). Omitted the size argument doesn't work either (a uniformly filled scatter/dot plot is shown).

Your size param is way way way too big. Scale it, maybe something like

norm = max(df['freq'])
df.plot.scatter(x='hour', y='weekday', s=df['freq'] / norm);

And just after posting this question (and hours of research that caused quite a headache) I found the answer. Matplotlibs scatter plot size parameter is not made for large absolute values and does not scale or take relative values, thus the "blue block" area covering the whole chart. By changing the code (adding a scaling factor) a nice chart is generated:

df.plot.scatter(x='hour', y='weekday', s=df['freq']*0.001);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM