原则上,问题与matlab2tikz imagesc TikZ/pgfplots 等效
有人能告诉我如何采用这个代码片段来绘制非对称矩阵但具有平方轴(内部没有任何间隙)
正如它应该不是由于存在差距,看起来像:
看起来应该如此不是例如,由于矩形轴:
摘录:
\documentclass[border=5mm]{standalone}
\usepackage{xcolor}
\definecolor{cr3}{RGB}{177,11,69}
\definecolor{cr2}{RGB}{210,210,210}
\definecolor{cr1}{RGB}{121,154,153}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{%
compat=newest,
tick label style={font=\small},
label style={font=\footnotesize},
legend style={font=\scriptsize,fill=none,draw=none},
every axis legend/.append style={legend image code/.code={\draw[mark repeat=2,mark phase=2,##1]plot coordinates {(0cm,0cm) (0.1cm,0cm) (0.2cm,0cm)};}},
}%
%*** matrix-plot style
\pgfplotsset{%
matrix plot/.style = {%
axis on top,
clip marker paths = true,
scale only axis,
% height = \nYdata//\nXdata/*\pgfkeysvalueof{/pgfplots/width},
enlarge x limits = {rel=0.5/\nXdata/},
enlarge y limits = {rel=0.5/\nYdata/},
scatter/use mapped color = {draw=mapped color, fill=mapped color},
scatter,
point meta = explicit,
mark = square*,
cycle list = {%
mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\nXdata/
}
},
}%
%*** number definition
\pgfkeys{%
/pgf/number format/set thousands separator={},
/pgf/number format/set decimal separator={.}
}%
%*** data table information
\usepackage{pgfplotstable}
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
header=false
}%
\begin{document}
\begin{tikzpicture}
%*** definition of datasize
\def\nXdata/{20},
\def\nYdata/{6},
%*** definition of limits
\def\min/{0.5},
\def\max/{1.5},
\def\lb/{1.0},
\def\ub/{1.0},
%*** axis
\begin{axis}[
width=5cm,
height=5cm,
matrix plot,
point meta min={\min/},
point meta max={\max/},
colormap={UIBK}{[0.1]
color(\min/-\min/)=(cr1);
color(\lb/-\min/)=(cr2);
color(\ub/-\min/)=(cr2);
color(\max/-\min/)=(cr3)},
%*** colorbar
colorbar horizontal,
colorbar style = {%
at={(0.0,1.30)},
anchor=south west,
width=1.0*\pgfkeysvalueof{/pgfplots/parent axis width},
height=0.3cm,
xmin=\min/,
xmax=\max/,
xtick={\min/,\lb/,\ub/,\max/},
mark = square*,},
colorbar sampled line,
%*** x-axis
xlabel = {$n$},
xmin = 1,
xmax = 20,
xtick = {1,5,10,15,20},
%*** y-axis
ylabel = {$\tau$},
ymin = 1,
ymax = 6,
ytick = {1,2,3,4,5,6},
yticklabels = {0.10,0.12,0.14,0.16,0.18,0.20},
]
\addplot table [meta index=2] {1.000000;1.000000;1.051819
1.000000;2.000000;1.000000
1.000000;3.000000;1.000000
1.000000;4.000000;1.000000
1.000000;5.000000;1.012168
1.000000;6.000000;0.988435
2.000000;1.000000;0.953648
2.000000;2.000000;0.945830
2.000000;3.000000;0.967785
2.000000;4.000000;0.980390
2.000000;5.000000;0.957779
2.000000;6.000000;0.973894
3.000000;1.000000;0.962710
3.000000;2.000000;0.949404
3.000000;3.000000;0.959728
3.000000;4.000000;0.972972
3.000000;5.000000;0.963546
3.000000;6.000000;0.979361
4.000000;1.000000;0.959866
4.000000;2.000000;0.984708
4.000000;3.000000;0.961893
4.000000;4.000000;0.998287
4.000000;5.000000;0.968716
4.000000;6.000000;0.962727
5.000000;1.000000;0.973517
5.000000;2.000000;0.975561
5.000000;3.000000;0.976335
5.000000;4.000000;0.976228
5.000000;5.000000;0.983381
5.000000;6.000000;0.968988
6.000000;1.000000;0.966111
6.000000;2.000000;0.984690
6.000000;3.000000;0.947801
6.000000;4.000000;0.984505
6.000000;5.000000;0.964116
6.000000;6.000000;0.972827
7.000000;1.000000;0.993063
7.000000;2.000000;0.953702
7.000000;3.000000;0.996289
7.000000;4.000000;0.970655
7.000000;5.000000;0.957275
7.000000;6.000000;0.925806
8.000000;1.000000;0.958390
8.000000;2.000000;0.998144
8.000000;3.000000;0.974472
8.000000;4.000000;0.954414
8.000000;5.000000;0.949770
8.000000;6.000000;0.918929
9.000000;1.000000;0.998319
9.000000;2.000000;0.980637
9.000000;3.000000;0.966380
9.000000;4.000000;0.973852
9.000000;5.000000;0.931611
9.000000;6.000000;0.939964
10.000000;1.000000;1.009831
10.000000;2.000000;0.997056
10.000000;3.000000;0.971533
10.000000;4.000000;0.950970
10.000000;5.000000;0.984151
10.000000;6.000000;0.939601
11.000000;1.000000;0.991757
11.000000;2.000000;0.986907
11.000000;3.000000;0.970439
11.000000;4.000000;1.000952
11.000000;5.000000;0.982607
11.000000;6.000000;0.963821
12.000000;1.000000;1.030766
12.000000;2.000000;1.012735
12.000000;3.000000;1.000013
12.000000;4.000000;1.014096
12.000000;5.000000;0.973391
12.000000;6.000000;0.984517
13.000000;1.000000;1.020537
13.000000;2.000000;0.997647
13.000000;3.000000;1.035671
13.000000;4.000000;0.998183
13.000000;5.000000;0.995325
13.000000;6.000000;0.975726
14.000000;1.000000;1.033529
14.000000;2.000000;1.026951
14.000000;3.000000;1.039208
14.000000;4.000000;1.001587
14.000000;5.000000;0.985112
14.000000;6.000000;1.029229
15.000000;1.000000;1.004259
15.000000;2.000000;1.049424
15.000000;3.000000;1.017412
15.000000;4.000000;1.006954
15.000000;5.000000;1.012810
15.000000;6.000000;1.084488
16.000000;1.000000;1.026232
16.000000;2.000000;1.073393
16.000000;3.000000;1.032529
16.000000;4.000000;1.010247
16.000000;5.000000;1.031920
16.000000;6.000000;1.059238
17.000000;1.000000;1.049910
17.000000;2.000000;1.027786
17.000000;3.000000;1.018022
17.000000;4.000000;1.015627
17.000000;5.000000;1.113215
17.000000;6.000000;1.080651
18.000000;1.000000;1.065341
18.000000;2.000000;1.041362
18.000000;3.000000;1.011830
18.000000;4.000000;1.058460
18.000000;5.000000;1.069346
18.000000;6.000000;1.058428
19.000000;1.000000;1.095343
19.000000;2.000000;1.021611
19.000000;3.000000;1.031146
19.000000;4.000000;1.122735
19.000000;5.000000;1.098571
19.000000;6.000000;1.088736
20.000000;1.000000;1.065167
20.000000;2.000000;1.005796
20.000000;3.000000;1.051143
20.000000;4.000000;1.078253
20.000000;5.000000;1.080351
20.000000;6.000000;1.069805
};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:
已实现颜色修改(使用 pgfplots 缩放颜色图)。
答案1
如果没有透明度,解决方案就相当直接,只需使用matrix plot*
PGFPlots v1.13 的功能(手册第 168 页第 4.6.12 节)。我稍微简化了您的示例,以便更容易看到要点。
\documentclass{standalone}
\usepackage{xcolor}
\definecolor{cr3}{RGB}{177,11,69}
\definecolor{cr2}{RGB}{210,210,210}
\definecolor{cr1}{RGB}{121,154,153}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
header=false
}
\begin{document}
\begin{tikzpicture}
\def\min/{0.92}, % originally: 0.5
\def\max/{1.12}, % originally: 1.5
\def\lb/{1.0},
\def\ub/{1.0},
\begin{axis}[
%*** general
width=5cm,
height=5cm,
%*** colormap
point meta min={\min/},
point meta max={\max/},
colormap={UIBK}{ % simplified to match non-uniform distances around 1
color=(cr1);
color=(cr2);
color=(cr3);
},
%*** colorbar
colorbar,
colorbar style={
ytick={\min/,\lb/,\ub/,\max/},
},
%*** x-axis
xlabel={$n$},
xmin=1,
xmax=20,
xtick={1,5,10,15,20},
%*** y-axis
ylabel={$\theta-\alpha$},
ymin=1,
ymax=6,
ytick={1,2,3,4,5,6,7,8},
yticklabels={0.03,0.04,0.05,0.06,0.10,0.20,0.30,0.40},
%
point meta=explicit, % to use explicitly given meta values
axis on top, % otherwise you won't see the ticks
enlargelimits={abs=0.5}, % increase axis limits half a step width
% which is the part drawn to each side at
% each given point
% if you want to draw a grid uncomment and adapt me
%faceted color=mapped color!80!black,
]
\addplot [
matrix plot*,
% if you want to draw a grid uncomment me, too
%shader=faceted,
] table [meta index=2] {
1.000000;1.000000;1.051819
1.000000;2.000000;1.000000
1.000000;3.000000;1.000000
1.000000;4.000000;1.000000
1.000000;5.000000;1.012168
1.000000;6.000000;0.988435
2.000000;1.000000;0.953648
2.000000;2.000000;0.945830
2.000000;3.000000;0.967785
2.000000;4.000000;0.980390
2.000000;5.000000;0.957779
2.000000;6.000000;0.973894
3.000000;1.000000;0.962710
3.000000;2.000000;0.949404
3.000000;3.000000;0.959728
3.000000;4.000000;0.972972
3.000000;5.000000;0.963546
3.000000;6.000000;0.979361
4.000000;1.000000;0.959866
4.000000;2.000000;0.984708
4.000000;3.000000;0.961893
4.000000;4.000000;0.998287
4.000000;5.000000;0.968716
4.000000;6.000000;0.962727
5.000000;1.000000;0.973517
5.000000;2.000000;0.975561
5.000000;3.000000;0.976335
5.000000;4.000000;0.976228
5.000000;5.000000;0.983381
5.000000;6.000000;0.968988
6.000000;1.000000;0.966111
6.000000;2.000000;0.984690
6.000000;3.000000;0.947801
6.000000;4.000000;0.984505
6.000000;5.000000;0.964116
6.000000;6.000000;0.972827
7.000000;1.000000;0.993063
7.000000;2.000000;0.953702
7.000000;3.000000;0.996289
7.000000;4.000000;0.970655
7.000000;5.000000;0.957275
7.000000;6.000000;0.925806
8.000000;1.000000;0.958390
8.000000;2.000000;0.998144
8.000000;3.000000;0.974472
8.000000;4.000000;0.954414
8.000000;5.000000;0.949770
8.000000;6.000000;0.918929
9.000000;1.000000;0.998319
9.000000;2.000000;0.980637
9.000000;3.000000;0.966380
9.000000;4.000000;0.973852
9.000000;5.000000;0.931611
9.000000;6.000000;0.939964
10.000000;1.000000;1.009831
10.000000;2.000000;0.997056
10.000000;3.000000;0.971533
10.000000;4.000000;0.950970
10.000000;5.000000;0.984151
10.000000;6.000000;0.939601
11.000000;1.000000;0.991757
11.000000;2.000000;0.986907
11.000000;3.000000;0.970439
11.000000;4.000000;1.000952
11.000000;5.000000;0.982607
11.000000;6.000000;0.963821
12.000000;1.000000;1.030766
12.000000;2.000000;1.012735
12.000000;3.000000;1.000013
12.000000;4.000000;1.014096
12.000000;5.000000;0.973391
12.000000;6.000000;0.984517
13.000000;1.000000;1.020537
13.000000;2.000000;0.997647
13.000000;3.000000;1.035671
13.000000;4.000000;0.998183
13.000000;5.000000;0.995325
13.000000;6.000000;0.975726
14.000000;1.000000;1.033529
14.000000;2.000000;1.026951
14.000000;3.000000;1.039208
14.000000;4.000000;1.001587
14.000000;5.000000;0.985112
14.000000;6.000000;1.029229
15.000000;1.000000;1.004259
15.000000;2.000000;1.049424
15.000000;3.000000;1.017412
15.000000;4.000000;1.006954
15.000000;5.000000;1.012810
15.000000;6.000000;1.084488
16.000000;1.000000;1.026232
16.000000;2.000000;1.073393
16.000000;3.000000;1.032529
16.000000;4.000000;1.010247
16.000000;5.000000;1.031920
16.000000;6.000000;1.059238
17.000000;1.000000;1.049910
17.000000;2.000000;1.027786
17.000000;3.000000;1.018022
17.000000;4.000000;1.015627
17.000000;5.000000;1.113215
17.000000;6.000000;1.080651
18.000000;1.000000;1.065341
18.000000;2.000000;1.041362
18.000000;3.000000;1.011830
18.000000;4.000000;1.058460
18.000000;5.000000;1.069346
18.000000;6.000000;1.058428
19.000000;1.000000;1.095343
19.000000;2.000000;1.021611
19.000000;3.000000;1.031146
19.000000;4.000000;1.122735
19.000000;5.000000;1.098571
19.000000;6.000000;1.088736
20.000000;1.000000;1.065167
20.000000;2.000000;1.005796
20.000000;3.000000;1.051143
20.000000;4.000000;1.078253
20.000000;5.000000;1.080351
20.000000;6.000000;1.069805
};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
最后,使用 matlab 翻译的 Python 脚本版本PGFPLOTS 中的条件透明表面我成功了:)
源代码:
\documentclass{standalone}
\usepackage{xcolor}
\definecolor{cr3}{RGB}{177,11,69}
\definecolor{cr2}{RGB}{210,210,210}
\definecolor{cr1}{RGB}{121,154,153}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
header=false
}%
\begin{document}
\begin{tikzpicture}
\def\min/{0.5},
\def\max/{1.5},
\def\lb/{1.0},
\def\ub/{1.0},
\begin{axis}[
%*** general
% view = {-40}{30}, %3D
view = {0}{90}, %2D
width=5cm,
height=5cm,
unbounded coords = jump,
%*** colormap
point meta min={\min/},
point meta max={\max/},
colormap={UIBK}{[0.1]
color(\min/-\min/)=(cr1);
color(\lb/-\min/)=(cr2);
color(\ub/-\min/)=(cr2);
color(\max/-\min/)=(cr3)},
%*** colorbar
colorbar,
colorbar style = {%
at={(1.1,0.0)},
anchor=south west,
height=1.0*\pgfkeysvalueof{/pgfplots/parent axis height},
width=0.2cm,
ymin=\min/,
ymax=\max/,
ytick={\min/,\lb/,\ub/,\max/},
mark = square*,},
%*** x-axis
xlabel = {$n$},
xmin = 1,
xmax = 21,
xtick = {1,5,10,15,20},
xticklabels = {1,5,10,15,20},
x tick label style={xshift=2,yshift=0},
%*** y-axis
ylabel = {$\theta-\alpha$},
ymin = 1,
ymax = 9,
ytick = {1,2,3,4,5,6,7,8},
yticklabels = {0.03,0.04,0.05,0.06,0.10,0.20,0.30,0.40},
y tick label style={xshift=0,yshift=6},
%*** zmin
zmin=\min/,
zmax=\max/,
]
\addplot3[surf,mark=none,mesh/cols=48,faceted color=gray,very thin] table {data/(n_thal)(2)(M_2_Mima_CCp50)(IM-i)(tau0.20)(ATC63)(Bilin)(4strsti)(R).csv};
\end{axis}
\end{tikzpicture}
\end{document}