Color coded table plot based on the values in a pandas dataframe
I have a dataframe df containing string values
a b c d
b c d a
I would like to produce a pdf plot based on the data in the df, with 4 cols and 2 rows, where each cell in the table plot has a color depending on the value in the df, a=blue, b=red, c=yellow, d=green.
Like this
Thanks in advance!
python pandas dataframe matplotlib
add a comment |
I have a dataframe df containing string values
a b c d
b c d a
I would like to produce a pdf plot based on the data in the df, with 4 cols and 2 rows, where each cell in the table plot has a color depending on the value in the df, a=blue, b=red, c=yellow, d=green.
Like this
Thanks in advance!
python pandas dataframe matplotlib
By "table" you mean aplt.tableor a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
I would probably map the characters to numbers first, then plot animshowplot of the data. You will need a custom colormap with the 4 colors in it.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:40
add a comment |
I have a dataframe df containing string values
a b c d
b c d a
I would like to produce a pdf plot based on the data in the df, with 4 cols and 2 rows, where each cell in the table plot has a color depending on the value in the df, a=blue, b=red, c=yellow, d=green.
Like this
Thanks in advance!
python pandas dataframe matplotlib
I have a dataframe df containing string values
a b c d
b c d a
I would like to produce a pdf plot based on the data in the df, with 4 cols and 2 rows, where each cell in the table plot has a color depending on the value in the df, a=blue, b=red, c=yellow, d=green.
Like this
Thanks in advance!
python pandas dataframe matplotlib
python pandas dataframe matplotlib
edited Nov 13 '18 at 18:08
Joe
6,00921429
6,00921429
asked Nov 13 '18 at 12:55
peter_parkerpeter_parker
174
174
By "table" you mean aplt.tableor a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
I would probably map the characters to numbers first, then plot animshowplot of the data. You will need a custom colormap with the 4 colors in it.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:40
add a comment |
By "table" you mean aplt.tableor a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
I would probably map the characters to numbers first, then plot animshowplot of the data. You will need a custom colormap with the 4 colors in it.
– ImportanceOfBeingErnest
Nov 13 '18 at 13:40
By "table" you mean a
plt.table or a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
By "table" you mean a
plt.table or a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
I would probably map the characters to numbers first, then plot an
imshow plot of the data. You will need a custom colormap with the 4 colors in it.– ImportanceOfBeingErnest
Nov 13 '18 at 13:40
I would probably map the characters to numbers first, then plot an
imshow plot of the data. You will need a custom colormap with the 4 colors in it.– ImportanceOfBeingErnest
Nov 13 '18 at 13:40
add a comment |
1 Answer
1
active
oldest
votes
You can do in this way:
from matplotlib import colors as c
color_map = 'a':1,'b':2,'c':3, 'd':4
cMap = c.ListedColormap(['g','b','y','r'])
df = df.replace(color_map)
fig, ax = plt.subplots()
ax.pcolor(df,cmap=cMap)
plt.show()

And If you want to remove the ticks, add plt.xticks() and plt.yticks()
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%2f53281495%2fcolor-coded-table-plot-based-on-the-values-in-a-pandas-dataframe%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
You can do in this way:
from matplotlib import colors as c
color_map = 'a':1,'b':2,'c':3, 'd':4
cMap = c.ListedColormap(['g','b','y','r'])
df = df.replace(color_map)
fig, ax = plt.subplots()
ax.pcolor(df,cmap=cMap)
plt.show()

And If you want to remove the ticks, add plt.xticks() and plt.yticks()
add a comment |
You can do in this way:
from matplotlib import colors as c
color_map = 'a':1,'b':2,'c':3, 'd':4
cMap = c.ListedColormap(['g','b','y','r'])
df = df.replace(color_map)
fig, ax = plt.subplots()
ax.pcolor(df,cmap=cMap)
plt.show()

And If you want to remove the ticks, add plt.xticks() and plt.yticks()
add a comment |
You can do in this way:
from matplotlib import colors as c
color_map = 'a':1,'b':2,'c':3, 'd':4
cMap = c.ListedColormap(['g','b','y','r'])
df = df.replace(color_map)
fig, ax = plt.subplots()
ax.pcolor(df,cmap=cMap)
plt.show()

And If you want to remove the ticks, add plt.xticks() and plt.yticks()
You can do in this way:
from matplotlib import colors as c
color_map = 'a':1,'b':2,'c':3, 'd':4
cMap = c.ListedColormap(['g','b','y','r'])
df = df.replace(color_map)
fig, ax = plt.subplots()
ax.pcolor(df,cmap=cMap)
plt.show()

And If you want to remove the ticks, add plt.xticks() and plt.yticks()
edited Nov 13 '18 at 14:43
answered Nov 13 '18 at 14:27
JoeJoe
6,00921429
6,00921429
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.
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%2f53281495%2fcolor-coded-table-plot-based-on-the-values-in-a-pandas-dataframe%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
By "table" you mean a
plt.tableor a subplot grid? I think you would benefit from describing much more in detail the desired output and also what other resources have not helped you achieve what you want.– ImportanceOfBeingErnest
Nov 13 '18 at 13:20
@ImportanceOfBeingErnest I added a picture of what I am looking for :)
– peter_parker
Nov 13 '18 at 13:36
I would probably map the characters to numbers first, then plot an
imshowplot of the data. You will need a custom colormap with the 4 colors in it.– ImportanceOfBeingErnest
Nov 13 '18 at 13:40