- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用以下代码从不同文件夹中的不同数据创建了 3 个带有 colorbar()
的 python 图:
import numpy as np
from matplotlib import pyplot as pp
pp.rcParams.update({'figure.autolayout': True})
data=np.loadtxt("performance.dat")
A=np.reshape(data, (21,21,4))
x=A[:,:,0]
y=A[:,:,1]
rn=A[:,:,3]
f=pp.figure()
ax=f.add_subplot(111, )
fs=20
for tick in ax.axes.xaxis.get_major_ticks():
tick.label.set_fontsize(fs)
for tick in ax.yaxis.get_major_ticks():
tick.label.set_fontsize(fs)
pp.pcolor(np.log10(x),np.log10(y),rn)
pp.clim(0,2)
pp.xlabel(r"$\log \, \sigma_1$", size=28)
pp.ylabel(r"$\log \, \sigma_2$",size=28)
pp.colorbar().ax.tick_params(labelsize=20)
pp.show()
然后我将它并排插入到我的 LaTeX 文件中:
\begin{figure}[H]
\makebox[\linewidth][c]{
\begin{subfigure}[b]{.4\textwidth}
\centering
\includegraphics[width=.95\textwidth, bb = -0 -0 530 420]{m200_l10_p90}%-0 -0 588 444
\end{subfigure}
%
\begin{subfigure}[b]{.4\textwidth}
\centering
\includegraphics[width=.95\textwidth, bb = -0 -0 530 420]{m200_l10_p95}%
\end{subfigure}
%
\begin{subfigure}[b]{.4\textwidth}
\centering
\includegraphics[width=.95\textwidth, bb = -0 -0 530 420]{m200_l10_P99}
\end{subfigure}
}
\caption{bla}
\label{fig:bla}
\end{figure}
我得到:
显然这看起来不太好,我玩过 LaTeX,直到现在这是我能得到的最好的,以使其可读。我的想法可能是只创建一个显示垂直颜色条的图(最后一个图),第一个图只有“y 标签”,中间一个图有“x 标签”,我认为这样看起来会更好。
我的问题是如何在不显示颜色条的情况下创建颜色条图?我试图评论 pp.colorbar().ax.tick_params(labelsize=20)
行,但这搞砸了剧情。
绘图仍然需要更大的标签和刻度字体大小。
最佳答案
您可以使用 genfromtxt
提供 genfromtxt
的路径,从不同的目录获取数据:
np.genfromtxt('/path/to/performance.dat')
您可以使用子图在一个图中创建所有 3 个热图。
然后,只需在右侧添加一个新轴,并在该 axes
上绘制 colorbar
(使用 cax
kwarg)。
最后,很容易只将 ylabel
添加到左图(仅将其放在 ax1
上)。
我使用 subplots_adjust
在合理的位置设置边距,并在右侧为颜色条腾出空间。您会注意到 subplots_adjust
命令的底部和顶部被重复用于制作颜色条轴,所以它们排列得很好。
import matplotlib.pyplot as plt
import numpy as np
# Sample data. You can get yours with np.genfromtxt('/path/to/performance.dat')
data1 = np.random.rand(20,20)*2
data2 = np.random.rand(20,20)*2
data3 = np.random.rand(20,20)*2
fig = plt.figure(figsize=(9,3))
bottom,top,left,right = 0.2,0.9,0.1,0.85
fig.subplots_adjust(bottom=bottom,left=left,right=right,top=top)
# fancy new colormap, just because...
plt.viridis()
# Add the 3 subplots
ax1 = fig.add_subplot(131)
ax2 = fig.add_subplot(132)
ax3 = fig.add_subplot(133)
# Plot the data
for ax,data in zip(fig.axes,[data1,data2,data3]):
p=ax.pcolor(data,vmin=0,vmax=2)
# xlabel on all subplots
ax.set_xlabel(r"$\log \, \sigma_1$", size=28)
# ylabel only on the left
ax1.set_ylabel(r"$\log \, \sigma_2$", size=28)
# add_axes takes (left,bottom,width,height)
# height is just top-bottom
cax = fig.add_axes([right+0.05,bottom,0.03,top-bottom])
fig.colorbar(p,cax=cax)
plt.show()
排列所有子图的另一种方法是使用 mpl_toolkits.axes_grid1
中的 AxesGrid
,它会自动执行所有操作。这是为 AxesGrid
修改的上面的脚本。
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import AxesGrid
# Sample data. You can get yours with np.genfromtxt('/path/to/performance.dat')
data1 = np.random.rand(20,20)*2
data2 = np.random.rand(20,20)*2
data3 = np.random.rand(20,20)*2
fig = plt.figure(figsize=(9,3))
fig.subplots_adjust(bottom=0.2)
plt.viridis()
grid = AxesGrid(fig, 111,
nrows_ncols=(1, 3),
axes_pad=0.2,
share_all=True,
label_mode="L",
cbar_location="right",
cbar_mode="single",
)
for ax,data in zip(grid,[data1,data2,data3]):
p=ax.pcolor(data,vmin=0,vmax=2)
ax.set_xlabel(r"$\log \, \sigma_1$", size=28)
grid[0].set_ylabel(r"$\log \, \sigma_2$", size=28)
grid.cbar_axes[0].colorbar(p)
plt.show()
关于python - 在 matplotlib 中创建没有颜色条的热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33804118/
我想要类似于以下伪代码的东西: while input is not None and timer = 5: print "took too long" else: print inp
如何将 MainEngine Observable 转换为 Cold?来自这个例子: public IObservable MainEngine { get
自从手表被发明以来,表盘的方圆之争就始终没有停下来过,在漫长的岁月中,无论是方形还是圆形表盘,人们都为其寻找到足够多的设计元素,让其肆意成长,这种生机与活力后来也延续到了智能手表上,在2014年,这
我正在学习 CUDA,试图解决一些标准问题。例如,我正在使用以下代码求解二维扩散方程。但我的结果与标准结果不同,我无法弄清楚。 //kernel definition __global__ void
我的 Web 应用程序使用 native dll 来实现其部分功能(其位置在 PATH 中提供)。一切正常,直到我对 WAR 进行更改并且 JBoss 热部署此 WAR。此时dll已经找不到了,需要手
我看到这个问题here 。这是关于实现每个发出的项目的延迟。这是根据accepted answer如何实现的: Observable.zip(Observable.range(1, 5) .g
我最近一直在进行冷迁移...这意味着我无法在进行迁移时从应用程序级别读取/写入数据库(维护页面)。 这样就不会因为更改结构而发生错误,而且如果负载很大,我也不希望 mysql 在迁移过程中崩溃。 我的
我是一名优秀的程序员,十分优秀!