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:
enter image description here



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?










share|improve this question






















  • 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















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:
enter image description here



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?










share|improve this question






















  • 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













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:
enter image description here



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?










share|improve this question













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:
enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 15:35









a1234

1881210




1881210












  • 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


















  • 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
















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












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.



Bar plot



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.



Bar plot with dates with autofmt






share|improve this answer



















  • 1




    Bingo! thanks for the help and clarification!
    – a1234
    Nov 9 at 19:01











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
});


}
});














draft saved

draft discarded


















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.



Bar plot



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.



Bar plot with dates with autofmt






share|improve this answer



















  • 1




    Bingo! thanks for the help and clarification!
    – a1234
    Nov 9 at 19:01















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.



Bar plot



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.



Bar plot with dates with autofmt






share|improve this answer



















  • 1




    Bingo! thanks for the help and clarification!
    – a1234
    Nov 9 at 19:01













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.



Bar plot



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.



Bar plot with dates with autofmt






share|improve this answer














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.



Bar plot



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.



Bar plot with dates with autofmt







share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini