Plotting histogram on python with dictionary [duplicate]
This question already has an answer here:
python: plot a bar using matplotlib using a dictionary
5 answers
I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
python matplotlib histogram
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
python: plot a bar using matplotlib using a dictionary
5 answers
I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
python matplotlib histogram
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
python: plot a bar using matplotlib using a dictionary
5 answers
I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
python matplotlib histogram
This question already has an answer here:
python: plot a bar using matplotlib using a dictionary
5 answers
I want to plot the following dictionary on python using matplotlib.pyplot as a histogram.
How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
This question already has an answer here:
python: plot a bar using matplotlib using a dictionary
5 answers
python matplotlib histogram
python matplotlib histogram
edited Nov 22 '18 at 13:26
Joe
6,05421429
6,05421429
asked Nov 22 '18 at 13:23
MohitMohit
112
112
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ImportanceOfBeingErnest
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:34
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
add a comment |
You can simply use:
plt.bar(data.keys(), data.values())
add a comment |
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
add a comment |
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
add a comment |
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
answered Nov 22 '18 at 13:31
blue_noteblue_note
11.8k32434
11.8k32434
add a comment |
add a comment |
You can simply use:
plt.bar(data.keys(), data.values())
add a comment |
You can simply use:
plt.bar(data.keys(), data.values())
add a comment |
You can simply use:
plt.bar(data.keys(), data.values())
You can simply use:
plt.bar(data.keys(), data.values())
answered Nov 22 '18 at 13:36
yatuyatu
11.7k31238
11.7k31238
add a comment |
add a comment |
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()
add a comment |
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()
add a comment |
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()
answered Nov 22 '18 at 13:35
JoeJoe
6,05421429
6,05421429
add a comment |
add a comment |