Seaborn style plot of pandas dataframeHow to make the equivalent of a seaborn heatmap?How do i get the x axis on top but keep a line on the bottomWrong ticks in colorbar using pgfplotsLocation and size of pgf plot axis in a tikzpicture - with tikz positioning library?How to prevent rounded and duplicated tick labels in pgfplots with fixed precision?pgfplots: percentage in matrix plotCenter the axes in the coordinate originscatter plot - mark absolute size from data and custom colormapPGFplots-warning: Sorry, the colorbar is uninitialised - your axis has no color dataPlotting a 3D data-set from a .csv fileUsing PGFPlots to plot Mathematica Interpolated Function
Where to find an interactive PDF or HTML version of the tex.web documentation?
Aftermath of nuclear disaster at Three Mile Island
Heisenberg uncertainty principle in daily life
How do I stop my characters falling in love?
Examples of simultaneous independent breakthroughs
Isolated audio without a transformer
Does academia have a lazy work culture?
The Sword in the Stone
Decreasing star size
Pointwise convergence of uniformly continuous functions to zero, but not uniformly
How acidic does a mixture have to be for milk to curdle?
Why do planes need a roll motion?
Finding minimum time for vehicle to reach to its destination
What does "see" in "the Holy See" mean?
Are there any examples of technologies have been lost over time?
The best place for swimming in Arctic Ocean
Send a single HTML email from Thunderbird, overriding the default "plain text" setting
Make AES more secure by randomising the blocks in an encrypted file
Is a fighting a fallen friend with the help of a redeemed villain story too much for one book
Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?
Interrupt pin type on the 6502
How to tar a list of directories only if they exist
How did Mysterio have these drones?
Why is it considered Acid Rain with pH <5.6
Seaborn style plot of pandas dataframe
How to make the equivalent of a seaborn heatmap?How do i get the x axis on top but keep a line on the bottomWrong ticks in colorbar using pgfplotsLocation and size of pgf plot axis in a tikzpicture - with tikz positioning library?How to prevent rounded and duplicated tick labels in pgfplots with fixed precision?pgfplots: percentage in matrix plotCenter the axes in the coordinate originscatter plot - mark absolute size from data and custom colormapPGFplots-warning: Sorry, the colorbar is uninitialised - your axis has no color dataPlotting a 3D data-set from a .csv fileUsing PGFPlots to plot Mathematica Interpolated Function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
There is a similar question like mine, but I am not satisfied with the answer, because the axis labels there are coordinates, while I am looking to also have the column and index labels written as text as in seaborn.
This is the output of from seaborn which I want to reproduce (never mind the colormap).

Here's the python code I use to generate an output for pgfplots to use.
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
for i in range(len(df.index)):
for j in range(len(df.columns)):
f.write(" n".format(j,i,df.values[i][j]))
f.write("n")
generate_file(df)
This create mwe.dat with the following content:
0 0 3
1 0 10
0 1 2
1 1 15
And this is my latex mwe for my current solution, lacking the text labels and the values written in the middle:
documentclass[tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[view=090,
colorbar,
]
addplot3[matrix plot,point meta=explicit] file mwe.dat;
endaxis
endtikzpicture
enddocument
This currently outputs this:

So I have two questions:
- how to add text labels to axes, instead of coordinates?
- how to write the value in the middle of the cell?
Since I will be using python anyway to generate the original dataframes, it is okay if I need python to actually generate the entire latex code, but I would prefer a solution, where python only generates a data file containing all info needed for the plot (I want to avoid changing things by hand).
pgfplots
add a comment |
There is a similar question like mine, but I am not satisfied with the answer, because the axis labels there are coordinates, while I am looking to also have the column and index labels written as text as in seaborn.
This is the output of from seaborn which I want to reproduce (never mind the colormap).

Here's the python code I use to generate an output for pgfplots to use.
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
for i in range(len(df.index)):
for j in range(len(df.columns)):
f.write(" n".format(j,i,df.values[i][j]))
f.write("n")
generate_file(df)
This create mwe.dat with the following content:
0 0 3
1 0 10
0 1 2
1 1 15
And this is my latex mwe for my current solution, lacking the text labels and the values written in the middle:
documentclass[tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[view=090,
colorbar,
]
addplot3[matrix plot,point meta=explicit] file mwe.dat;
endaxis
endtikzpicture
enddocument
This currently outputs this:

So I have two questions:
- how to add text labels to axes, instead of coordinates?
- how to write the value in the middle of the cell?
Since I will be using python anyway to generate the original dataframes, it is okay if I need python to actually generate the entire latex code, but I would prefer a solution, where python only generates a data file containing all info needed for the plot (I want to avoid changing things by hand).
pgfplots
Would be nice if you could addmwe.datto the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.
– Torbjørn T.
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@DJP there was something off with the generatedmwe.dat.
– fbence
6 hours ago
add a comment |
There is a similar question like mine, but I am not satisfied with the answer, because the axis labels there are coordinates, while I am looking to also have the column and index labels written as text as in seaborn.
This is the output of from seaborn which I want to reproduce (never mind the colormap).

Here's the python code I use to generate an output for pgfplots to use.
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
for i in range(len(df.index)):
for j in range(len(df.columns)):
f.write(" n".format(j,i,df.values[i][j]))
f.write("n")
generate_file(df)
This create mwe.dat with the following content:
0 0 3
1 0 10
0 1 2
1 1 15
And this is my latex mwe for my current solution, lacking the text labels and the values written in the middle:
documentclass[tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[view=090,
colorbar,
]
addplot3[matrix plot,point meta=explicit] file mwe.dat;
endaxis
endtikzpicture
enddocument
This currently outputs this:

So I have two questions:
- how to add text labels to axes, instead of coordinates?
- how to write the value in the middle of the cell?
Since I will be using python anyway to generate the original dataframes, it is okay if I need python to actually generate the entire latex code, but I would prefer a solution, where python only generates a data file containing all info needed for the plot (I want to avoid changing things by hand).
pgfplots
There is a similar question like mine, but I am not satisfied with the answer, because the axis labels there are coordinates, while I am looking to also have the column and index labels written as text as in seaborn.
This is the output of from seaborn which I want to reproduce (never mind the colormap).

Here's the python code I use to generate an output for pgfplots to use.
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
for i in range(len(df.index)):
for j in range(len(df.columns)):
f.write(" n".format(j,i,df.values[i][j]))
f.write("n")
generate_file(df)
This create mwe.dat with the following content:
0 0 3
1 0 10
0 1 2
1 1 15
And this is my latex mwe for my current solution, lacking the text labels and the values written in the middle:
documentclass[tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[view=090,
colorbar,
]
addplot3[matrix plot,point meta=explicit] file mwe.dat;
endaxis
endtikzpicture
enddocument
This currently outputs this:

So I have two questions:
- how to add text labels to axes, instead of coordinates?
- how to write the value in the middle of the cell?
Since I will be using python anyway to generate the original dataframes, it is okay if I need python to actually generate the entire latex code, but I would prefer a solution, where python only generates a data file containing all info needed for the plot (I want to avoid changing things by hand).
pgfplots
pgfplots
edited 6 hours ago
fbence
asked 8 hours ago
fbencefbence
7611 gold badge5 silver badges19 bronze badges
7611 gold badge5 silver badges19 bronze badges
Would be nice if you could addmwe.datto the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.
– Torbjørn T.
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@DJP there was something off with the generatedmwe.dat.
– fbence
6 hours ago
add a comment |
Would be nice if you could addmwe.datto the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.
– Torbjørn T.
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@DJP there was something off with the generatedmwe.dat.
– fbence
6 hours ago
Would be nice if you could add
mwe.dat to the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.– Torbjørn T.
6 hours ago
Would be nice if you could add
mwe.dat to the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.– Torbjørn T.
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@DJP there was something off with the generated
mwe.dat.– fbence
6 hours ago
@DJP there was something off with the generated
mwe.dat.– fbence
6 hours ago
add a comment |
2 Answers
2
active
oldest
votes
If you change the Python code to also print the column names and index values:
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
f.write("x y z xl yln")
for i,line in enumerate(df.values):
for j,val in enumerate(line):
f.write(" n".format(j,i,val, df.columns[j], df.index[j]))
f.write("n")
generate_file(df)
So mwe.dat becomes
x y z xl yl
0 0 3 foo foo2
1 0 10 bar bar2
0 1 2 foo foo2
1 1 15 bar bar2
Then you can set the tick locations and read the ticklabels from the file like in the code below. x/yticklabels from table seems to assume that the file has a header row, hence the addition of that.
nodes near coords, nodes near coords align=center can be used to place the values in the cells.
Note the use of addplot ... table instead of addplot ... file.
documentclass[border=5mm,tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
view=090,
colorbar,
xtick=data,
ytick=data,
xticklabels from table=mwe.datxl,
yticklabels from table=mwe.datyl,
yticklabel style=rotate=90
]
addplot3[matrix plot, nodes near coords, nodes near coords align=center] table mwe.dat;
endaxis
endtikzpicture
enddocument

I removedpoint meta=explicitbecause that caused an error.
– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of thexticklabelandyticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info throughmwe.dat?
– fbence
6 hours ago
|
show 8 more comments
Here's one way
documentclass[tikz,border=20pt]standalone
usepackagepgfplots, filecontents
pgfplotssetcompat=1.13
begindocument
beginfilecontents*mwe.dat
0 0 3
1 0 10
0 1 2
1 1 15
endfilecontents*
begintikzpicture
beginaxis[view=090, colorbar,hide axis,nodes near coords = pgfmathprintnumberpgfplotspointmeta]
addplot [matrix plot*,point meta=explicit] file mwe.dat;
node[] at (axis cs: -0.010,-.65) foo;
node[] at (axis cs: 0.980,-.65) bar;
node[rotate=90] at (axis cs: -0.59,.01) bar2;
node[rotate=90] at (axis cs: -0.590,1.0) foo2;
endaxis
endtikzpicture
enddocument
The output from Gummi is:
With respect to your question "how to add text labels to axes, instead of coordinates?" I did hide axis in setting the axis. Then I added nodes with the labels you wanted and positioned them and rotated them where you wanted. As for "how to write the value in the middle of the cell?", I added nodes near coords = pgfmathprintnumberpgfplotspointmeta in setting up the axis. I'm wondering about the data file matching up with your picture, though, as the numbers are in the wrong row. The colors are in different rows as well.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2ftex.stackexchange.com%2fquestions%2f501835%2fseaborn-style-plot-of-pandas-dataframe%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
If you change the Python code to also print the column names and index values:
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
f.write("x y z xl yln")
for i,line in enumerate(df.values):
for j,val in enumerate(line):
f.write(" n".format(j,i,val, df.columns[j], df.index[j]))
f.write("n")
generate_file(df)
So mwe.dat becomes
x y z xl yl
0 0 3 foo foo2
1 0 10 bar bar2
0 1 2 foo foo2
1 1 15 bar bar2
Then you can set the tick locations and read the ticklabels from the file like in the code below. x/yticklabels from table seems to assume that the file has a header row, hence the addition of that.
nodes near coords, nodes near coords align=center can be used to place the values in the cells.
Note the use of addplot ... table instead of addplot ... file.
documentclass[border=5mm,tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
view=090,
colorbar,
xtick=data,
ytick=data,
xticklabels from table=mwe.datxl,
yticklabels from table=mwe.datyl,
yticklabel style=rotate=90
]
addplot3[matrix plot, nodes near coords, nodes near coords align=center] table mwe.dat;
endaxis
endtikzpicture
enddocument

I removedpoint meta=explicitbecause that caused an error.
– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of thexticklabelandyticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info throughmwe.dat?
– fbence
6 hours ago
|
show 8 more comments
If you change the Python code to also print the column names and index values:
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
f.write("x y z xl yln")
for i,line in enumerate(df.values):
for j,val in enumerate(line):
f.write(" n".format(j,i,val, df.columns[j], df.index[j]))
f.write("n")
generate_file(df)
So mwe.dat becomes
x y z xl yl
0 0 3 foo foo2
1 0 10 bar bar2
0 1 2 foo foo2
1 1 15 bar bar2
Then you can set the tick locations and read the ticklabels from the file like in the code below. x/yticklabels from table seems to assume that the file has a header row, hence the addition of that.
nodes near coords, nodes near coords align=center can be used to place the values in the cells.
Note the use of addplot ... table instead of addplot ... file.
documentclass[border=5mm,tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
view=090,
colorbar,
xtick=data,
ytick=data,
xticklabels from table=mwe.datxl,
yticklabels from table=mwe.datyl,
yticklabel style=rotate=90
]
addplot3[matrix plot, nodes near coords, nodes near coords align=center] table mwe.dat;
endaxis
endtikzpicture
enddocument

I removedpoint meta=explicitbecause that caused an error.
– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of thexticklabelandyticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info throughmwe.dat?
– fbence
6 hours ago
|
show 8 more comments
If you change the Python code to also print the column names and index values:
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
f.write("x y z xl yln")
for i,line in enumerate(df.values):
for j,val in enumerate(line):
f.write(" n".format(j,i,val, df.columns[j], df.index[j]))
f.write("n")
generate_file(df)
So mwe.dat becomes
x y z xl yl
0 0 3 foo foo2
1 0 10 bar bar2
0 1 2 foo foo2
1 1 15 bar bar2
Then you can set the tick locations and read the ticklabels from the file like in the code below. x/yticklabels from table seems to assume that the file has a header row, hence the addition of that.
nodes near coords, nodes near coords align=center can be used to place the values in the cells.
Note the use of addplot ... table instead of addplot ... file.
documentclass[border=5mm,tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
view=090,
colorbar,
xtick=data,
ytick=data,
xticklabels from table=mwe.datxl,
yticklabels from table=mwe.datyl,
yticklabel style=rotate=90
]
addplot3[matrix plot, nodes near coords, nodes near coords align=center] table mwe.dat;
endaxis
endtikzpicture
enddocument

If you change the Python code to also print the column names and index values:
import pandas as pd
import seaborn as sns
data = [[3, 10], [2, 15]]
df = pd.DataFrame(data, columns = ['foo', 'bar'],index = ["foo2","bar2"])
sns.heatmap(df,annot=True)
def generate_file(df):
with open("mwe.dat","w") as f:
f.write("x y z xl yln")
for i,line in enumerate(df.values):
for j,val in enumerate(line):
f.write(" n".format(j,i,val, df.columns[j], df.index[j]))
f.write("n")
generate_file(df)
So mwe.dat becomes
x y z xl yl
0 0 3 foo foo2
1 0 10 bar bar2
0 1 2 foo foo2
1 1 15 bar bar2
Then you can set the tick locations and read the ticklabels from the file like in the code below. x/yticklabels from table seems to assume that the file has a header row, hence the addition of that.
nodes near coords, nodes near coords align=center can be used to place the values in the cells.
Note the use of addplot ... table instead of addplot ... file.
documentclass[border=5mm,tikz]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
view=090,
colorbar,
xtick=data,
ytick=data,
xticklabels from table=mwe.datxl,
yticklabels from table=mwe.datyl,
yticklabel style=rotate=90
]
addplot3[matrix plot, nodes near coords, nodes near coords align=center] table mwe.dat;
endaxis
endtikzpicture
enddocument

edited 3 hours ago
answered 6 hours ago
Torbjørn T.Torbjørn T.
163k13 gold badges267 silver badges453 bronze badges
163k13 gold badges267 silver badges453 bronze badges
I removedpoint meta=explicitbecause that caused an error.
– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of thexticklabelandyticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info throughmwe.dat?
– fbence
6 hours ago
|
show 8 more comments
I removedpoint meta=explicitbecause that caused an error.
– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of thexticklabelandyticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info throughmwe.dat?
– fbence
6 hours ago
I removed
point meta=explicit because that caused an error.– Torbjørn T.
6 hours ago
I removed
point meta=explicit because that caused an error.– Torbjørn T.
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
It's working in my code. I can remove my code in a moment as you posted first.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
I guess I started answer before you because when I posted, your answer was there already.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
My colors and numbers were in different blocks than both of yours, so I'm assuming there is a mistake.
– DJP
6 hours ago
@TorbjørnT. So if I want to automate the creation of the
xticklabel and yticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info through mwe.dat?– fbence
6 hours ago
@TorbjørnT. So if I want to automate the creation of the
xticklabel and yticklabel, the best if if I just write a latex template with the python code? No clear way to pass this info through mwe.dat?– fbence
6 hours ago
|
show 8 more comments
Here's one way
documentclass[tikz,border=20pt]standalone
usepackagepgfplots, filecontents
pgfplotssetcompat=1.13
begindocument
beginfilecontents*mwe.dat
0 0 3
1 0 10
0 1 2
1 1 15
endfilecontents*
begintikzpicture
beginaxis[view=090, colorbar,hide axis,nodes near coords = pgfmathprintnumberpgfplotspointmeta]
addplot [matrix plot*,point meta=explicit] file mwe.dat;
node[] at (axis cs: -0.010,-.65) foo;
node[] at (axis cs: 0.980,-.65) bar;
node[rotate=90] at (axis cs: -0.59,.01) bar2;
node[rotate=90] at (axis cs: -0.590,1.0) foo2;
endaxis
endtikzpicture
enddocument
The output from Gummi is:
With respect to your question "how to add text labels to axes, instead of coordinates?" I did hide axis in setting the axis. Then I added nodes with the labels you wanted and positioned them and rotated them where you wanted. As for "how to write the value in the middle of the cell?", I added nodes near coords = pgfmathprintnumberpgfplotspointmeta in setting up the axis. I'm wondering about the data file matching up with your picture, though, as the numbers are in the wrong row. The colors are in different rows as well.
add a comment |
Here's one way
documentclass[tikz,border=20pt]standalone
usepackagepgfplots, filecontents
pgfplotssetcompat=1.13
begindocument
beginfilecontents*mwe.dat
0 0 3
1 0 10
0 1 2
1 1 15
endfilecontents*
begintikzpicture
beginaxis[view=090, colorbar,hide axis,nodes near coords = pgfmathprintnumberpgfplotspointmeta]
addplot [matrix plot*,point meta=explicit] file mwe.dat;
node[] at (axis cs: -0.010,-.65) foo;
node[] at (axis cs: 0.980,-.65) bar;
node[rotate=90] at (axis cs: -0.59,.01) bar2;
node[rotate=90] at (axis cs: -0.590,1.0) foo2;
endaxis
endtikzpicture
enddocument
The output from Gummi is:
With respect to your question "how to add text labels to axes, instead of coordinates?" I did hide axis in setting the axis. Then I added nodes with the labels you wanted and positioned them and rotated them where you wanted. As for "how to write the value in the middle of the cell?", I added nodes near coords = pgfmathprintnumberpgfplotspointmeta in setting up the axis. I'm wondering about the data file matching up with your picture, though, as the numbers are in the wrong row. The colors are in different rows as well.
add a comment |
Here's one way
documentclass[tikz,border=20pt]standalone
usepackagepgfplots, filecontents
pgfplotssetcompat=1.13
begindocument
beginfilecontents*mwe.dat
0 0 3
1 0 10
0 1 2
1 1 15
endfilecontents*
begintikzpicture
beginaxis[view=090, colorbar,hide axis,nodes near coords = pgfmathprintnumberpgfplotspointmeta]
addplot [matrix plot*,point meta=explicit] file mwe.dat;
node[] at (axis cs: -0.010,-.65) foo;
node[] at (axis cs: 0.980,-.65) bar;
node[rotate=90] at (axis cs: -0.59,.01) bar2;
node[rotate=90] at (axis cs: -0.590,1.0) foo2;
endaxis
endtikzpicture
enddocument
The output from Gummi is:
With respect to your question "how to add text labels to axes, instead of coordinates?" I did hide axis in setting the axis. Then I added nodes with the labels you wanted and positioned them and rotated them where you wanted. As for "how to write the value in the middle of the cell?", I added nodes near coords = pgfmathprintnumberpgfplotspointmeta in setting up the axis. I'm wondering about the data file matching up with your picture, though, as the numbers are in the wrong row. The colors are in different rows as well.
Here's one way
documentclass[tikz,border=20pt]standalone
usepackagepgfplots, filecontents
pgfplotssetcompat=1.13
begindocument
beginfilecontents*mwe.dat
0 0 3
1 0 10
0 1 2
1 1 15
endfilecontents*
begintikzpicture
beginaxis[view=090, colorbar,hide axis,nodes near coords = pgfmathprintnumberpgfplotspointmeta]
addplot [matrix plot*,point meta=explicit] file mwe.dat;
node[] at (axis cs: -0.010,-.65) foo;
node[] at (axis cs: 0.980,-.65) bar;
node[rotate=90] at (axis cs: -0.59,.01) bar2;
node[rotate=90] at (axis cs: -0.590,1.0) foo2;
endaxis
endtikzpicture
enddocument
The output from Gummi is:
With respect to your question "how to add text labels to axes, instead of coordinates?" I did hide axis in setting the axis. Then I added nodes with the labels you wanted and positioned them and rotated them where you wanted. As for "how to write the value in the middle of the cell?", I added nodes near coords = pgfmathprintnumberpgfplotspointmeta in setting up the axis. I'm wondering about the data file matching up with your picture, though, as the numbers are in the wrong row. The colors are in different rows as well.
edited 6 hours ago
answered 6 hours ago
DJPDJP
8,2992 gold badges18 silver badges32 bronze badges
8,2992 gold badges18 silver badges32 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- 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%2ftex.stackexchange.com%2fquestions%2f501835%2fseaborn-style-plot-of-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
Would be nice if you could add
mwe.datto the question as well, so people don't have to run your Python code. Edit: and if I do run the Python code, the LaTeX example throws an error.– Torbjørn T.
6 hours ago
@TorbjørnT. Thanks, good idea, I updated the question.
– fbence
6 hours ago
@DJP there was something off with the generated
mwe.dat.– fbence
6 hours ago