Python matplotlib - How to draw line chart with many series?
I had a python pandas dataframe like below:
test_score param # of Nodes
0 0.497852 relu 1
1 0.68935 relu 2
2 0.701165 relu 3
3 0.735223 identity 1
4 0.735064 identity 2
5 0.735691 identity 3
6 0.72651 logistic 1
7 0.664837 logistic 2
8 0.743445 logistic 3
9 0.705182 tanh 1
10 0.673399 tanh 2
11 0.684129 tanh 3
I would like to draw the line chart with x axis as "# of Nodes", y axis as "test_score", and four param values "relu, identity, logistic, tanh" as 4 series lines.
Could this chart be plotted in python matplotlib?
python pandas dataframe matplotlib
add a comment |
I had a python pandas dataframe like below:
test_score param # of Nodes
0 0.497852 relu 1
1 0.68935 relu 2
2 0.701165 relu 3
3 0.735223 identity 1
4 0.735064 identity 2
5 0.735691 identity 3
6 0.72651 logistic 1
7 0.664837 logistic 2
8 0.743445 logistic 3
9 0.705182 tanh 1
10 0.673399 tanh 2
11 0.684129 tanh 3
I would like to draw the line chart with x axis as "# of Nodes", y axis as "test_score", and four param values "relu, identity, logistic, tanh" as 4 series lines.
Could this chart be plotted in python matplotlib?
python pandas dataframe matplotlib
1
Did you try anything? Likedf.groupby("param").plot(x="# of nodes", y="test_score")
?
– ImportanceOfBeingErnest
Nov 11 at 18:16
add a comment |
I had a python pandas dataframe like below:
test_score param # of Nodes
0 0.497852 relu 1
1 0.68935 relu 2
2 0.701165 relu 3
3 0.735223 identity 1
4 0.735064 identity 2
5 0.735691 identity 3
6 0.72651 logistic 1
7 0.664837 logistic 2
8 0.743445 logistic 3
9 0.705182 tanh 1
10 0.673399 tanh 2
11 0.684129 tanh 3
I would like to draw the line chart with x axis as "# of Nodes", y axis as "test_score", and four param values "relu, identity, logistic, tanh" as 4 series lines.
Could this chart be plotted in python matplotlib?
python pandas dataframe matplotlib
I had a python pandas dataframe like below:
test_score param # of Nodes
0 0.497852 relu 1
1 0.68935 relu 2
2 0.701165 relu 3
3 0.735223 identity 1
4 0.735064 identity 2
5 0.735691 identity 3
6 0.72651 logistic 1
7 0.664837 logistic 2
8 0.743445 logistic 3
9 0.705182 tanh 1
10 0.673399 tanh 2
11 0.684129 tanh 3
I would like to draw the line chart with x axis as "# of Nodes", y axis as "test_score", and four param values "relu, identity, logistic, tanh" as 4 series lines.
Could this chart be plotted in python matplotlib?
python pandas dataframe matplotlib
python pandas dataframe matplotlib
edited Nov 11 at 18:28
asked Nov 11 at 18:11
Jenny Jing Yu
123
123
1
Did you try anything? Likedf.groupby("param").plot(x="# of nodes", y="test_score")
?
– ImportanceOfBeingErnest
Nov 11 at 18:16
add a comment |
1
Did you try anything? Likedf.groupby("param").plot(x="# of nodes", y="test_score")
?
– ImportanceOfBeingErnest
Nov 11 at 18:16
1
1
Did you try anything? Like
df.groupby("param").plot(x="# of nodes", y="test_score")
?– ImportanceOfBeingErnest
Nov 11 at 18:16
Did you try anything? Like
df.groupby("param").plot(x="# of nodes", y="test_score")
?– ImportanceOfBeingErnest
Nov 11 at 18:16
add a comment |
2 Answers
2
active
oldest
votes
You can start by grouping by param
, then iterating through your groups and plotting:
g = df.groupby('param')
for p, data in g:
plt.plot(data['# of Nodes'], data['test_score'], label=p)
plt.legend()
plt.xlabel('# of Nodes')
plt.ylabel('Test Score')
plt.show()
add a comment |
If you have all nodes for all parameters like in your example you can .pivot
your DataFrame
to a more suitable format for plotting them all.
df.pivot(index='# of Nodes', columns='param', values='test_score').plot()
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',
autoActivateHeartbeat: false,
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%2f53251711%2fpython-matplotlib-how-to-draw-line-chart-with-many-series%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can start by grouping by param
, then iterating through your groups and plotting:
g = df.groupby('param')
for p, data in g:
plt.plot(data['# of Nodes'], data['test_score'], label=p)
plt.legend()
plt.xlabel('# of Nodes')
plt.ylabel('Test Score')
plt.show()
add a comment |
You can start by grouping by param
, then iterating through your groups and plotting:
g = df.groupby('param')
for p, data in g:
plt.plot(data['# of Nodes'], data['test_score'], label=p)
plt.legend()
plt.xlabel('# of Nodes')
plt.ylabel('Test Score')
plt.show()
add a comment |
You can start by grouping by param
, then iterating through your groups and plotting:
g = df.groupby('param')
for p, data in g:
plt.plot(data['# of Nodes'], data['test_score'], label=p)
plt.legend()
plt.xlabel('# of Nodes')
plt.ylabel('Test Score')
plt.show()
You can start by grouping by param
, then iterating through your groups and plotting:
g = df.groupby('param')
for p, data in g:
plt.plot(data['# of Nodes'], data['test_score'], label=p)
plt.legend()
plt.xlabel('# of Nodes')
plt.ylabel('Test Score')
plt.show()
answered Nov 11 at 18:17
sacul
29.9k41740
29.9k41740
add a comment |
add a comment |
If you have all nodes for all parameters like in your example you can .pivot
your DataFrame
to a more suitable format for plotting them all.
df.pivot(index='# of Nodes', columns='param', values='test_score').plot()
add a comment |
If you have all nodes for all parameters like in your example you can .pivot
your DataFrame
to a more suitable format for plotting them all.
df.pivot(index='# of Nodes', columns='param', values='test_score').plot()
add a comment |
If you have all nodes for all parameters like in your example you can .pivot
your DataFrame
to a more suitable format for plotting them all.
df.pivot(index='# of Nodes', columns='param', values='test_score').plot()
If you have all nodes for all parameters like in your example you can .pivot
your DataFrame
to a more suitable format for plotting them all.
df.pivot(index='# of Nodes', columns='param', values='test_score').plot()
edited Nov 11 at 21:43
answered Nov 11 at 21:33
ALollz
11.1k31334
11.1k31334
add a comment |
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%2f53251711%2fpython-matplotlib-how-to-draw-line-chart-with-many-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
1
Did you try anything? Like
df.groupby("param").plot(x="# of nodes", y="test_score")
?– ImportanceOfBeingErnest
Nov 11 at 18:16