Python matplotlib - How to draw line chart with many series?
up vote
-1
down vote
favorite
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 |
up vote
-1
down vote
favorite
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 |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
up vote
0
down vote
accepted
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 |
up vote
1
down vote
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 |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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
29k41639
29k41639
add a comment |
add a comment |
up vote
1
down vote
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 |
up vote
1
down vote
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 |
up vote
1
down vote
up vote
1
down vote
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
10.6k31234
10.6k31234
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