Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lineplot function #1285

Merged
merged 76 commits into from
Nov 30, 2017
Merged

Add lineplot function #1285

merged 76 commits into from
Nov 30, 2017

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Sep 17, 2017

This PR adds a major new function, lineplot, that replaces tsplot while behaving much more like other seaborn functions (the categorical plotters) and adding some new capabilities (subsetting with different visual semantics on up to three dimensions, mapping the hue variable numerically, and handling dates properly).

The basic signature is similar to other functions:

lineplot(x, y, <semantic mappers>, data, <control kwargs>)

but with three parameters that determine subsetting/semantic mapping: hue, size, and style. These operate independently, so you can in principle show up to five variables on one plot (but be careful: many such plots will be very hard to interpret). The multiple semantics should also make it easy to generate plots that are accessible (i.e. using more than just color to map some variable) without much effort.

Here are some quick examples. For more information, I've copied the new tutorial notebook source to a gist.

fmri = sns.load_dataset("fmri")
sns.lineplot(x="timepoint", y="signal", data=fmri)

image

sns.lineplot(x="timepoint", y="signal", hue="event", style="event",
             markers=True, dashes=False, data=fmri)

image

sns.lineplot(x="timepoint", y="signal", hue="region", style="event", data=fmri)

image

sns.lineplot(x="time", y="firing_rate",
             hue="choice", size="coherence",
             legend="full", data=dots)

image

values = np.random.randn(365, 4).cumsum(axis=0)
dates = pd.date_range("1 1 2016", periods=365, freq="D")
data = pd.DataFrame(values, dates, columns=["A", "B", "C", "D"]).rolling(7).mean()

sns.lineplot(data=data, palette="tab10", linewidth=2.5)

image

What's more, most of the underlying architecture is going to be re-used to support a forthcoming scatterplot function that will behavior similarly while drawing scatterplots instead of line plots. However because that's not implemented yet, it's possible that doing so will force some small changes in lineplot behavior. That means I wouldn't use lineplot in production quite yet, but definitely start throwing some real datasets at it.

TODO

  • Clean up style- and size-related code
  • Clean up estimation code
  • Axes labeling
  • Legends
  • Decisions about default estimator/ci behavior
  • Update tsplot deprecation message
  • Unit tests
  • Release notes
  • Docstring / API examples
  • Gallery examples
  • Tutorial documentation

Related TODOs outside the scope of this PR:

  • Implement scatterplot
  • Improve colormap handling with numeric hue data: current behavior uses the rcParams image colormap (like matplotlib functions), but this is often suboptimal for lines/points because it often includes high luminance colors that give very low contrast with the background. Ideally matplotlib 2.0 would have had different colormaps for image/object data, but this was unfortunately rejected.
  • Improve "ticking" for brief legends
  • Implement units for faster bootstrapping in the case of repeated measures data
  • Also allow units to draw multiple unconnected lines with the same semantics (e.g. to plot individual subject data without differentiating) #

@codecov-io
Copy link

codecov-io commented Sep 30, 2017

Codecov Report

Merging #1285 into master will increase coverage by 0.36%.
The diff coverage is 97.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1285      +/-   ##
==========================================
+ Coverage   93.86%   94.23%   +0.36%     
==========================================
  Files          14       15       +1     
  Lines        3814     4214     +400     
==========================================
+ Hits         3580     3971     +391     
- Misses        234      243       +9
Impacted Files Coverage Δ
seaborn/categorical.py 96.68% <ø> (ø) ⬆️
seaborn/timeseries.py 70.32% <ø> (ø) ⬆️
seaborn/axisgrid.py 96.44% <0%> (ø) ⬆️
seaborn/__init__.py 100% <100%> (ø) ⬆️
seaborn/algorithms.py 100% <100%> (ø) ⬆️
seaborn/utils.py 87.35% <60%> (-0.54%) ⬇️
seaborn/basic.py 98.18% <98.18%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9eaaa53...b882bf1. Read the comment docs.

@beojan
Copy link

beojan commented Oct 7, 2017

Can we have the ability to specify the uncertainties rather than using bootstrapping?

@mwaskom
Copy link
Owner Author

mwaskom commented Oct 7, 2017

@beojan no, sorry, that's not the way things work in seaborn

@mwaskom mwaskom force-pushed the basic_plots branch 3 times, most recently from 5d07870 to 277ebd7 Compare October 8, 2017 14:37
@mwaskom mwaskom changed the title WIP: Add lineplot function Add lineplot function Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants