matplotlib double bar graph with pandas series
up vote
0
down vote
favorite
I have the following:
indyes = tuple(yesSeries.index)
indno = tuple(nodSeries.index)
width = 3
p1 = plt.bar(indyes, yesSeries, label="Example one", color='SkyBlue')
p2 = plt.bar(indno, nodSeries, label="Example two", color='IndianRed')
plt.legend()
plt.xlabel('bar number')
plt.ylabel('bar height')
plt.title('Epic GraphnAnother Line! Whoa')
plt.show()
It plots my graph as a stacked bar graph:
When I try to add + width
to the second bar graph, indno + width
so they are not stacked, rather side by side I get the following error: TypeError: can only concatenate tuple (not "int") to tuple
.
I have set my Pandas Series into a tuple to extract the date and count information.
How can I get a plot with 2 horizontal bar graphs?
pandas matplotlib tuples bar-chart
|
show 2 more comments
up vote
0
down vote
favorite
I have the following:
indyes = tuple(yesSeries.index)
indno = tuple(nodSeries.index)
width = 3
p1 = plt.bar(indyes, yesSeries, label="Example one", color='SkyBlue')
p2 = plt.bar(indno, nodSeries, label="Example two", color='IndianRed')
plt.legend()
plt.xlabel('bar number')
plt.ylabel('bar height')
plt.title('Epic GraphnAnother Line! Whoa')
plt.show()
It plots my graph as a stacked bar graph:
When I try to add + width
to the second bar graph, indno + width
so they are not stacked, rather side by side I get the following error: TypeError: can only concatenate tuple (not "int") to tuple
.
I have set my Pandas Series into a tuple to extract the date and count information.
How can I get a plot with 2 horizontal bar graphs?
pandas matplotlib tuples bar-chart
What's the reason to use atuple
here? Do you want to add 3 days to each item in the index?
– ImportanceOfBeingErnest
Nov 9 at 16:01
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following:
indyes = tuple(yesSeries.index)
indno = tuple(nodSeries.index)
width = 3
p1 = plt.bar(indyes, yesSeries, label="Example one", color='SkyBlue')
p2 = plt.bar(indno, nodSeries, label="Example two", color='IndianRed')
plt.legend()
plt.xlabel('bar number')
plt.ylabel('bar height')
plt.title('Epic GraphnAnother Line! Whoa')
plt.show()
It plots my graph as a stacked bar graph:
When I try to add + width
to the second bar graph, indno + width
so they are not stacked, rather side by side I get the following error: TypeError: can only concatenate tuple (not "int") to tuple
.
I have set my Pandas Series into a tuple to extract the date and count information.
How can I get a plot with 2 horizontal bar graphs?
pandas matplotlib tuples bar-chart
I have the following:
indyes = tuple(yesSeries.index)
indno = tuple(nodSeries.index)
width = 3
p1 = plt.bar(indyes, yesSeries, label="Example one", color='SkyBlue')
p2 = plt.bar(indno, nodSeries, label="Example two", color='IndianRed')
plt.legend()
plt.xlabel('bar number')
plt.ylabel('bar height')
plt.title('Epic GraphnAnother Line! Whoa')
plt.show()
It plots my graph as a stacked bar graph:
When I try to add + width
to the second bar graph, indno + width
so they are not stacked, rather side by side I get the following error: TypeError: can only concatenate tuple (not "int") to tuple
.
I have set my Pandas Series into a tuple to extract the date and count information.
How can I get a plot with 2 horizontal bar graphs?
pandas matplotlib tuples bar-chart
pandas matplotlib tuples bar-chart
asked Nov 9 at 15:35
a1234
1881210
1881210
What's the reason to use atuple
here? Do you want to add 3 days to each item in the index?
– ImportanceOfBeingErnest
Nov 9 at 16:01
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29
|
show 2 more comments
What's the reason to use atuple
here? Do you want to add 3 days to each item in the index?
– ImportanceOfBeingErnest
Nov 9 at 16:01
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29
What's the reason to use a
tuple
here? Do you want to add 3 days to each item in the index?– ImportanceOfBeingErnest
Nov 9 at 16:01
What's the reason to use a
tuple
here? Do you want to add 3 days to each item in the index?– ImportanceOfBeingErnest
Nov 9 at 16:01
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I believe that what you are looking for can be done creating a DataFrame
from your Series
and then using the plot.bar
function.
In below code I generate data and create the graph as you may want to.
import matplotlib.pyplot as plt
import pandas as pd
times = pd.date_range('2018-09-01', periods=7, freq='5D')
yesSeries = pd.Series([1800,2000,3000,1000,2000,1500,1700], index=times)
nodSeries = pd.Series([200,500,700,600,300,50,0], index=times)
df = pd.DataFrame({"Example one":yesSeries,"Example two":nodSeries})
ax = df.plot.bar(color=["SkyBlue","IndianRed"], rot=0, title="Epic GraphnAnother Line! Whoa")
ax.set_xlabel("date")
ax.set_ylabel("counts")
ax.xaxis.set_major_formatter(plt.FixedFormatter(times.strftime("%b %d %Y")))
plt.show()
This results in below graph.
If it seems that the dates appear to be cluttered you can insert below line before the plt.show()
code:
plt.gcf().autofmt_xdate()
Which would result in below graph.
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228762%2fmatplotlib-double-bar-graph-with-pandas-series%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I believe that what you are looking for can be done creating a DataFrame
from your Series
and then using the plot.bar
function.
In below code I generate data and create the graph as you may want to.
import matplotlib.pyplot as plt
import pandas as pd
times = pd.date_range('2018-09-01', periods=7, freq='5D')
yesSeries = pd.Series([1800,2000,3000,1000,2000,1500,1700], index=times)
nodSeries = pd.Series([200,500,700,600,300,50,0], index=times)
df = pd.DataFrame({"Example one":yesSeries,"Example two":nodSeries})
ax = df.plot.bar(color=["SkyBlue","IndianRed"], rot=0, title="Epic GraphnAnother Line! Whoa")
ax.set_xlabel("date")
ax.set_ylabel("counts")
ax.xaxis.set_major_formatter(plt.FixedFormatter(times.strftime("%b %d %Y")))
plt.show()
This results in below graph.
If it seems that the dates appear to be cluttered you can insert below line before the plt.show()
code:
plt.gcf().autofmt_xdate()
Which would result in below graph.
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
add a comment |
up vote
1
down vote
accepted
I believe that what you are looking for can be done creating a DataFrame
from your Series
and then using the plot.bar
function.
In below code I generate data and create the graph as you may want to.
import matplotlib.pyplot as plt
import pandas as pd
times = pd.date_range('2018-09-01', periods=7, freq='5D')
yesSeries = pd.Series([1800,2000,3000,1000,2000,1500,1700], index=times)
nodSeries = pd.Series([200,500,700,600,300,50,0], index=times)
df = pd.DataFrame({"Example one":yesSeries,"Example two":nodSeries})
ax = df.plot.bar(color=["SkyBlue","IndianRed"], rot=0, title="Epic GraphnAnother Line! Whoa")
ax.set_xlabel("date")
ax.set_ylabel("counts")
ax.xaxis.set_major_formatter(plt.FixedFormatter(times.strftime("%b %d %Y")))
plt.show()
This results in below graph.
If it seems that the dates appear to be cluttered you can insert below line before the plt.show()
code:
plt.gcf().autofmt_xdate()
Which would result in below graph.
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I believe that what you are looking for can be done creating a DataFrame
from your Series
and then using the plot.bar
function.
In below code I generate data and create the graph as you may want to.
import matplotlib.pyplot as plt
import pandas as pd
times = pd.date_range('2018-09-01', periods=7, freq='5D')
yesSeries = pd.Series([1800,2000,3000,1000,2000,1500,1700], index=times)
nodSeries = pd.Series([200,500,700,600,300,50,0], index=times)
df = pd.DataFrame({"Example one":yesSeries,"Example two":nodSeries})
ax = df.plot.bar(color=["SkyBlue","IndianRed"], rot=0, title="Epic GraphnAnother Line! Whoa")
ax.set_xlabel("date")
ax.set_ylabel("counts")
ax.xaxis.set_major_formatter(plt.FixedFormatter(times.strftime("%b %d %Y")))
plt.show()
This results in below graph.
If it seems that the dates appear to be cluttered you can insert below line before the plt.show()
code:
plt.gcf().autofmt_xdate()
Which would result in below graph.
I believe that what you are looking for can be done creating a DataFrame
from your Series
and then using the plot.bar
function.
In below code I generate data and create the graph as you may want to.
import matplotlib.pyplot as plt
import pandas as pd
times = pd.date_range('2018-09-01', periods=7, freq='5D')
yesSeries = pd.Series([1800,2000,3000,1000,2000,1500,1700], index=times)
nodSeries = pd.Series([200,500,700,600,300,50,0], index=times)
df = pd.DataFrame({"Example one":yesSeries,"Example two":nodSeries})
ax = df.plot.bar(color=["SkyBlue","IndianRed"], rot=0, title="Epic GraphnAnother Line! Whoa")
ax.set_xlabel("date")
ax.set_ylabel("counts")
ax.xaxis.set_major_formatter(plt.FixedFormatter(times.strftime("%b %d %Y")))
plt.show()
This results in below graph.
If it seems that the dates appear to be cluttered you can insert below line before the plt.show()
code:
plt.gcf().autofmt_xdate()
Which would result in below graph.
edited Nov 9 at 17:21
answered Nov 9 at 16:37
Cedric Zoppolo
1,21011327
1,21011327
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
add a comment |
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
1
1
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
Bingo! thanks for the help and clarification!
– a1234
Nov 9 at 19:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228762%2fmatplotlib-double-bar-graph-with-pandas-series%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What's the reason to use a
tuple
here? Do you want to add 3 days to each item in the index?– ImportanceOfBeingErnest
Nov 9 at 16:01
@ ImportanceOfBeingErnest I have my dataframe grouped by a timestamp, and my final dataset is a pandas.core.series.Series with a timestamp and counts. I'm using the tuple to access the timestamp and counts in the series for my x and y vales in my plot. The plot seems to be working fine, I prefer 2 bars rather than a stacked bar.
– a1234
Nov 9 at 16:08
Not sure if that answers my question. Anyways, you might also decide to provide a Minimal, Complete, and Verifiable example here, such that people can simply provide an answer without understanding the motivation.
– ImportanceOfBeingErnest
Nov 9 at 16:11
@ ImportanceOfBeingErnest No, I do not want to add 3 days. I want to have 2 horizontal bar graphs, and not stacked bar graphs.
– a1234
Nov 9 at 16:27
Horizontal bar graphs are created via barh.
– ImportanceOfBeingErnest
Nov 9 at 16:29