making seaborn heatmap from DataFrame plot to be aware of data rangesMaking heatmap from pandas DataFrameDelete column from pandas DataFrame by column nameSelect rows from a DataFrame based on values in a column in pandasHow to make IPython notebook matplotlib plot inlineGet list from pandas DataFrame column headersSeaborn plots not showing upHow to save a Seaborn plot into a fileUsing matplotlib *without* TCLTypeError when plotting heatmap with seabornmatplotlib implot not showing correct axis values when plotting pandas dataframe, seaborn shows correct axis values but doesn't show x and y on figure
How can I raise concerns with a new DM about XP splitting?
Stereotypical names
Can I create an upright 7-foot × 5-foot wall with the Minor Illusion spell?
What (else) happened July 1st 1858 in London?
Why are on-board computers allowed to change controls without notifying the pilots?
Can I Retrieve Email Addresses from BCC?
Is there an Impartial Brexit Deal comparison site?
Simulating a probability of 1 of 2^N with less than N random bits
Why does this part of the Space Shuttle launch pad seem to be floating in air?
Calculating the number of days between 2 dates in Excel
Is the next prime number always the next number divisible by the current prime number, except for any numbers previously divisible by primes?
Partial sums of primes
How can I successfully establish a nationwide combat training program for a large country?
Is infinity mathematically observable?
Latex for-and in equation
Pronouncing Homer as in modern Greek
Are Warlocks Arcane or Divine?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How to interpret the phrase "t’en a fait voir à toi"?
Proof of Lemma: Every integer can be written as a product of primes
Can I rely on these GitHub repository files?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
node command while defining a coordinate in TikZ
Is there a problem with hiding "forgot password" until it's needed?
making seaborn heatmap from DataFrame plot to be aware of data ranges
Making heatmap from pandas DataFrameDelete column from pandas DataFrame by column nameSelect rows from a DataFrame based on values in a column in pandasHow to make IPython notebook matplotlib plot inlineGet list from pandas DataFrame column headersSeaborn plots not showing upHow to save a Seaborn plot into a fileUsing matplotlib *without* TCLTypeError when plotting heatmap with seabornmatplotlib implot not showing correct axis values when plotting pandas dataframe, seaborn shows correct axis values but doesn't show x and y on figure
How can one make seaborn heatmap (created from a pandas DataFrame plot) to be aware of the data ranges? I.e. when I hover the mouse pointer over the plot, I can see in the bottom right corner of the plot window "x= y=", while I want to see coordinates of the point on the plot I am hovering over (for example, "x=25.6, y=3.3"), assuming, of course, that the input DataFrame contains a 2D histogram with equal size bins along each axis.
Alternatively, maybe I could create such plot in a different way to achieve the same effect? For example, with ax.hist2d I get it out of the box, but I want to be able to compute with custom code content of each bin and make it effectively a heatmap plot (with color coding of the bin contents).
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
sns.heatmap(df, annot=True)
plt.show(block=False)
Thank you for your help!
pandas matplotlib plot seaborn heatmap
add a comment |
How can one make seaborn heatmap (created from a pandas DataFrame plot) to be aware of the data ranges? I.e. when I hover the mouse pointer over the plot, I can see in the bottom right corner of the plot window "x= y=", while I want to see coordinates of the point on the plot I am hovering over (for example, "x=25.6, y=3.3"), assuming, of course, that the input DataFrame contains a 2D histogram with equal size bins along each axis.
Alternatively, maybe I could create such plot in a different way to achieve the same effect? For example, with ax.hist2d I get it out of the box, but I want to be able to compute with custom code content of each bin and make it effectively a heatmap plot (with color coding of the bin contents).
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
sns.heatmap(df, annot=True)
plt.show(block=False)
Thank you for your help!
pandas matplotlib plot seaborn heatmap
add a comment |
How can one make seaborn heatmap (created from a pandas DataFrame plot) to be aware of the data ranges? I.e. when I hover the mouse pointer over the plot, I can see in the bottom right corner of the plot window "x= y=", while I want to see coordinates of the point on the plot I am hovering over (for example, "x=25.6, y=3.3"), assuming, of course, that the input DataFrame contains a 2D histogram with equal size bins along each axis.
Alternatively, maybe I could create such plot in a different way to achieve the same effect? For example, with ax.hist2d I get it out of the box, but I want to be able to compute with custom code content of each bin and make it effectively a heatmap plot (with color coding of the bin contents).
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
sns.heatmap(df, annot=True)
plt.show(block=False)
Thank you for your help!
pandas matplotlib plot seaborn heatmap
How can one make seaborn heatmap (created from a pandas DataFrame plot) to be aware of the data ranges? I.e. when I hover the mouse pointer over the plot, I can see in the bottom right corner of the plot window "x= y=", while I want to see coordinates of the point on the plot I am hovering over (for example, "x=25.6, y=3.3"), assuming, of course, that the input DataFrame contains a 2D histogram with equal size bins along each axis.
Alternatively, maybe I could create such plot in a different way to achieve the same effect? For example, with ax.hist2d I get it out of the box, but I want to be able to compute with custom code content of each bin and make it effectively a heatmap plot (with color coding of the bin contents).
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
sns.heatmap(df, annot=True)
plt.show(block=False)
Thank you for your help!
pandas matplotlib plot seaborn heatmap
pandas matplotlib plot seaborn heatmap
asked Mar 21 at 14:38
S.VS.V
1809
1809
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you replace sns.heatmap(...) by ax.imshow(..), you're close to what you need. You can then set the extent of the image to the data range you need.
import numpy as np; np.random.seed(42)
import pandas as pd
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
dx = np.diff(df.columns)[0]/2
dy = np.diff(df.index)[0]/2
extent = [df.columns.min()-dx, df.columns.max()+dx,
df.index.min()-dy, df.index.max()+dy]
ax.imshow(df, extent=extent, aspect="auto")
plt.show()

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%2f55282940%2fmaking-seaborn-heatmap-from-dataframe-plot-to-be-aware-of-data-ranges%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
If you replace sns.heatmap(...) by ax.imshow(..), you're close to what you need. You can then set the extent of the image to the data range you need.
import numpy as np; np.random.seed(42)
import pandas as pd
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
dx = np.diff(df.columns)[0]/2
dy = np.diff(df.index)[0]/2
extent = [df.columns.min()-dx, df.columns.max()+dx,
df.index.min()-dy, df.index.max()+dy]
ax.imshow(df, extent=extent, aspect="auto")
plt.show()

add a comment |
If you replace sns.heatmap(...) by ax.imshow(..), you're close to what you need. You can then set the extent of the image to the data range you need.
import numpy as np; np.random.seed(42)
import pandas as pd
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
dx = np.diff(df.columns)[0]/2
dy = np.diff(df.index)[0]/2
extent = [df.columns.min()-dx, df.columns.max()+dx,
df.index.min()-dy, df.index.max()+dy]
ax.imshow(df, extent=extent, aspect="auto")
plt.show()

add a comment |
If you replace sns.heatmap(...) by ax.imshow(..), you're close to what you need. You can then set the extent of the image to the data range you need.
import numpy as np; np.random.seed(42)
import pandas as pd
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
dx = np.diff(df.columns)[0]/2
dy = np.diff(df.index)[0]/2
extent = [df.columns.min()-dx, df.columns.max()+dx,
df.index.min()-dy, df.index.max()+dy]
ax.imshow(df, extent=extent, aspect="auto")
plt.show()

If you replace sns.heatmap(...) by ax.imshow(..), you're close to what you need. You can then set the extent of the image to the data range you need.
import numpy as np; np.random.seed(42)
import pandas as pd
import matplotlib.pyplot as plt
Index = [ 1.0, 2.0, 3.0, 4.0, 5.0]
Cols = [10.0, 20.0, 30.0, 40.0, 50.0]
df = pd.DataFrame(abs(np.random.randn(5, 5)),
index=Index, columns=Cols)
plt.close(1)
fig,ax = plt.subplots(num=1)
dx = np.diff(df.columns)[0]/2
dy = np.diff(df.index)[0]/2
extent = [df.columns.min()-dx, df.columns.max()+dx,
df.index.min()-dy, df.index.max()+dy]
ax.imshow(df, extent=extent, aspect="auto")
plt.show()

answered Mar 21 at 15:37
ImportanceOfBeingErnestImportanceOfBeingErnest
139k13161239
139k13161239
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%2f55282940%2fmaking-seaborn-heatmap-from-dataframe-plot-to-be-aware-of-data-ranges%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