Blog - bar#25
Open
kdorr wants to merge 3 commits into
Open
Conversation
story645
reviewed
Aug 20, 2018
| ## Matplotlib | ||
| This is a little more complicated in Matplotlib. Since Matplotlib is procedural, we have to manually tell Matplotlib to stack the bars. Also notice that we are calling a new function now (`ax.bar()`) to get a bar plot. | ||
|
|
||
| To stack the bars, we have to create new subset dataframes and then plot each one separately (specifying that bottom of one plot should be the top of another `bottom=a_scores`). One way to do this is to subset via indexing (option 1). Another way to do this is to use the `df.groupby()` function (option 2). |
Member
There was a problem hiding this comment.
Worried that this phrasing may be confusing since the bottom=a uses the top of a as the bottom of b. Maybe just state it explicitly? In this example, we first plot group a. Then we plot group b, using the bottom=a kwarg to plot b starting from the top of each a bar (and yes that can be phrased more cleanly too)
tacaswell
reviewed
Aug 20, 2018
| fig, ax = plt.subplots() | ||
|
|
||
| (_, a), (_, b) = df.groupby('variable') | ||
| ax.bar(a['group'], a['scores'], label='a') |
Member
There was a problem hiding this comment.
This might be clearer as
bottom = np.zeros(len(a['group'])
for label, scores in df.groupby('variable');
ax.bar(scoren['group'], scores['scores'], bottom=bottom, label=label)
bottom += scores['scores']
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the bar chart section from the blog post Nabarun and I were working on.