Export marine thermal insulation to full pgf

I am trying to build a heat map with the sea and export it to pgf for easy import into latex. This works more or less, the only thing that bothers me is that the color bar is exported as an additional png.

So, if I run export to pgf, I get the following:

  • test.pgf
  • test img0.png

This is definitely undesirable since png doesn't scale well. Some MWEs:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

df = pd.DataFrame.from_csv("test.csv", sep=',')

sns.set('paper', 'white', rc={'font.size': 10, 'axes.labelsize': 10, 'legend.fontsize': 8, 'axes.titlesize': 10,
                              'xtick.labelsize': 8,
                              'ytick.labelsize': 8, "pgf.rcfonts": False})
plt.rc('font', **{'family': 'serif', 'serif': ['Times']})
plt.rc('text', usetex=True)
fig = plt.figure()
ax = sns.heatmap(df, linewidths=.5)
fig.savefig('test.pdf')
fig.savefig('test.pgf')

And the contents of test.csv:

0,1,2,3,4
1,1,1,1,1
2,2,2,2,2
3,3,3,3,3

Does anyone have a solution to include a colored string in pgf output?

+4
source share
1 answer

, pgf/tikz.

-, matplotlib (.. ) pgf, png ( op).

matplotlib2tikz. quadmesh png, . , , , Axes , png.

, , .

:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.DataFrame.from_csv("test.csv", sep=',')

sns.set('paper', 'white',
        rc={'font.size': 10, 'axes.labelsize': 10,
            'legend.fontsize': 8, 'axes.titlesize': 10,
            'xtick.labelsize': 8,'ytick.labelsize': 8, 
            "pgf.rcfonts": False,
           })
plt.rc('font', **{'family': 'serif', 'serif': ['Times']})
plt.rc('text', usetex=True)
fig, ax = plt.subplots(figsize=(6,6))
ax = sns.heatmap(df, linewidths=.5, ax=ax, cbar=False)
fig.savefig('heatmap_nocbar.pgf')

, cbar=False

:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from matplotlib2tikz import save as tikz_save

df = pd.DataFrame.from_csv("test.csv", sep=',')

sns.set('paper', 'white',
        rc={'font.size': 10, 'axes.labelsize': 10,
            'legend.fontsize': 8, 'axes.titlesize': 10,
            'xtick.labelsize': 8,'ytick.labelsize': 8, 
            "pgf.rcfonts": False,
           })
plt.rc('font', **{'family': 'serif', 'serif': ['Times']})
plt.rc('text', usetex=True)
fig, ax = plt.subplots()
ax = sns.heatmap(df, linewidths=.5, ax=ax, )
tikz_save('colormap.tex', figure=fig, strict=True)

. , , .

colormap.tex , , .

colormap.tex:

\begin{tikzpicture}

\begin{axis}[

... % definition of axis: delete these lines

colorbar,
colormap={mymap}{[1pt]
...

, :

\begin{tikzpicture}

\begin{axis}[
hide axis,
colorbar,
colormap={mymap}{[1pt]
...

\end{axis}:

]
... %delete these lines
\end{axis}

, github

tex

\input{heatmap_nocbar.pgf}
\input{colorbar.tex}

, github.

, , , , matplotlib matplotlib2tikz, .

+3

Source: https://habr.com/ru/post/1679711/


All Articles