0

I have a dataframe with various parameters (continuous time-series data) and other columns to filter out various conditions; these are made up of 1 when the condition is true and NaN when the condition is false.

If I plot a parameter and then plot it again just in the gate, I can do:

df.parameter.plot()
df.groupby('filter_column').parameter.plot(style='bo')

This example works fine, but if I want to plot using a line (style='b-' for example) it then joins the groups of filtered data with a line

A work-around is to create intermediate series, or multiply the two columns within a matplotlib call:

series = df.parameter * df.filter_column
series.plot(style='b-')

plt.plot(df.parameter * df.filter_column,'b-')

I'm not a fan of this type of plot statement or creating the intermediate columns. It would be really useful to have the direct groupby line plot deal with the NAs in the same way as a series.

Does anyone have any more elegant workarounds for this?

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
BMichell
  • 3,581
  • 5
  • 23
  • 31
  • Could you include an image of the two graphs? – crow_t_robot Jan 07 '16 at 16:37
  • No really - but it's the same issue as the second plot in this post - i.e. the group-by plotting does not treat a gap between data in the same way as discontinuous data in a Dataframe column or a series, and this seems inconsistent. http://stackoverflow.com/questions/15258656/how-to-plot-a-sparse-with-gaps-line-with-its-segments-colored-according-to-som – BMichell Jan 07 '16 at 16:57
  • I may not be visualizing correctly, but this post has two options ("linestyle=None" or resampling) that may be useful: http://stackoverflow.com/questions/16454183/matplotlib-remove-interpolation-for-missing-data – crow_t_robot Jan 07 '16 at 19:25
  • It's fine if it's a column - the gaps are NaN and it plots correctly - the issue is specifically using groupby – BMichell Jan 08 '16 at 08:24

0 Answers0