- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
是否可以像下图那样使用对数刻度的颜色条级别?
这是一些可以实现的示例代码:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
delta = 0.025
x = y = np.arange(0, 3.01, delta)
X, Y = np.meshgrid(x, y)
Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 1e6 * (Z1* Z2)
fig=plt.figure()
ax1 = fig.add_subplot(111)
lvls = np.logspace(0,4,20)
CF = ax1.contourf(X,Y,Z,
norm = LogNorm(),
levels = lvls
)
CS = ax1.contour(X,Y,Z,
norm = LogNorm(),
colors = 'k',
levels = lvls
)
cbar = plt.colorbar(CF, ticks=lvls, format='%.4f')
plt.show()
我在 Windows 7 上使用 python 2.7.3 和 matplotlib 1.1.1。
最佳答案
我建议按如下方式生成伪彩条(解释见评论):
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
import matplotlib.gridspec as gridspec
delta = 0.025
x = y = np.arange(0, 3.01, delta)
X, Y = np.meshgrid(x, y)
Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 1e6 * (Z1 * Z2)
fig=plt.figure()
#
# define 2 subplots, using gridspec to control the
# width ratios:
#
# note: you have to import matplotlib.gridspec for this
#
gs = gridspec.GridSpec(1, 2,width_ratios=[15,1])
# the 1st subplot
ax1 = plt.subplot(gs[0])
lvls = np.logspace(0,4,20)
CF = ax1.contourf(X,Y,Z,
norm = LogNorm(),
levels = lvls
)
CS = ax1.contour(X,Y,Z,
norm = LogNorm(),
colors = 'k',
levels = lvls
)
#
# the pseudo-colorbar
#
# the 2nd subplot
ax2 = plt.subplot(gs[1])
#
# new levels!
#
# np.logspace gives you logarithmically spaced levels -
# this, however, is not what you want in your colorbar
#
# you want equally spaced labels for each exponential group:
#
levls = np.linspace(1,10,10)
levls = np.concatenate((levls[:-1],np.linspace(10,100,10)))
levls = np.concatenate((levls[:-1],np.linspace(100,1000,10)))
levls = np.concatenate((levls[:-1],np.linspace(1000,10000,10)))
#
# simple x,y setup for a contourf plot to serve as colorbar
#
XC = [np.zeros(len(levls)), np.ones(len(levls))]
YC = [levls, levls]
CM = ax2.contourf(XC,YC,YC, levels=levls, norm = LogNorm())
# log y-scale
ax2.set_yscale('log')
# y-labels on the right
ax2.yaxis.tick_right()
# no x-ticks
ax2.set_xticks([])
plt.show()
这会给你一个这样的情节:
编辑
或者,在调用 colorbar
时使用新级别和 spacing='proportional'
选项:
替换这一行:
lvls = np.logspace(0,4,20)
这些:
lvls = np.linspace(1,10,5)
lvls = np.concatenate((lvls[:-1],np.linspace(10,100,5)))
lvls = np.concatenate((lvls[:-1],np.linspace(100,1000,5)))
lvls = np.concatenate((lvls[:-1],np.linspace(1000,10000,5)))
替换这一行:
cbar = plt.colorbar(CF, ticks=lvls, format='%.4f')
有了这个:
cbar = plt.colorbar(CF, ticks=lvls, format='%.2f', spacing='proportional')
你最终会得到这个情节:
(只是更改了格式
,因为新的刻度不需要 4 位小数)
编辑 2
如果你想像我用过的那样自动生成关卡,你可以考虑这段代码:
levels = []
LAST_EXP = 4
N_LEVELS = 5
for E in range(0,LAST_EXP):
levels = np.concatenate((levels[:-1],np.linspace(10**E,10**(E+1),N_LEVELS)))
关于python - matplotlib 等高线图 : proportional colorbar levels in logarithmic scale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18191867/
这应该是非常基本的,我希望有人可以帮助我。我通过以下调用运行了主成分分析: pca <- princomp(....) summary(pca) 摘要 pca 返回此描述:
这是我的测试代码:http://jsfiddle.net/Zx4fg/ 为什么圆在 Canvas 上看起来像椭圆? 我想将网络摄像头的快照保存为图像,但生成的图像不符合比例。 我的真实代码是: ctx
这是我的测试代码:http://jsfiddle.net/Zx4fg/ 为什么圆在 Canvas 上看起来像椭圆? 我想将网络摄像头的快照保存为图像,但生成的图像不符合比例。 我的真实代码是: ctx
问题: iOS8/Safari 似乎不理解/不支持包含视口(viewport)单元的媒体查询,例如:(max-height: 175vw)。不过它在 iOS9 设备上工作得很好。我尝试使用 max-a
假设我有一个如下所示的数据集: > dput(df) structure(list(Fruit = c("Apple", "Apple", "Apple", "Apple", "Apple", "Ap
我尝试减小视频的尺寸: ffmpeg -i input.mp4 -y -acodec aac -ac 2 -ab 160k -vcodec libx264 -vf "scale=-1:'min(720
我正在使用 Google 柱形图来可视化数据。 问题: 不幸的是,对于某个输入,柱形条的高度不成比例。 错误重现: I reconstructed this in a simple JsFiddle
这是我正在寻找的示例: 我查看了文档中的所有示例,但找不到类似的图表。任何帮助将不胜感激。 最佳答案 这里有一个方法: using Plots @userplot StackedArea # a si
这是我正在寻找的示例: 我查看了文档中的所有示例,但找不到类似的图表。任何帮助将不胜感激。 最佳答案 这里有一个方法: using Plots @userplot StackedArea # a si
我正在制作一个响应式网站,其标题设置为调整大小。在该图像上,我必须在 x,y 位置放置另一个较小的图像(它必须链接出来)。我的问题是如何在网站重新调整大小时保持比例?我可以用百分比定义宽度,但是高
我发现这个网站非常有用 Vertically Responsive Design : Keeping Things Above The Fold其中展示了如何创建在调整浏览器窗口高度(而非宽度)时缩放
我一直在开发一款需要球与球碰撞的游戏,但我似乎找不到任何解决这个问题的方法,我几乎遇到了碰撞,因为球正朝着正确的方向前进,但速度却困惑了. 一旦球互相撞击,水平方向 (x) 会非常用力地弹开,而垂直方
我想弄清楚 Android 的 PSS 是如何计算的。 我找到一个 article说明如下。 The "proportional set size" (PSS) of a process is the
想象一下有四个项目的堆栈 View ,填充了一些东西。 (比如说,填满屏幕)。 请注意,有三个间隙,ABC。 (注意——每个黄色 block 的高度都是固定的。) (只有间隙会发生变化,具体取决于堆栈
后续问题 to my other one ; 如何启用按比例调整大小?我认为这行得通,但行不通: import javax.swing.JButton; import javax.swing.JFra
似乎如果你在 raphael 中缩放一个集合,它会缩放里面的元素,但不会按比例平移它们。因此,例如,如果我的集合中有两个相邻的方 block ,并且我缩放了设置,则这些方 block 开始相互重叠,而
我正在学习 WPF,但不知道如何确保我的按钮呈方形。 这是我的 XAML 标记: Very very long text 为 Width
我目前正在研究语音分类问题。我每个类(class)有 1000 个音频文件,有 7 个这样的类(class)。我需要增强数据以实现更高的准确性。我正在使用 librosa 库进行数据增强。对于每个音频
我想创建与决策树中每个类别成反比的预测概率。类似于所描述的here第 9 页 4.1 中的公式。我该如何引用我的代码来做到这一点: import numpy as np import pandas a
我有两个标签绿色和黄色,我试图让它们始终与屏幕宽度成相同比例。我尝试了宽高比和更改优先级等但没有得到最终结果。如果有人能帮助我,我将不胜感激 最佳答案 您需要为与 super View 的宽度相关的
我是一名优秀的程序员,十分优秀!