- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
尝试将观察结果分别绘制到每个观察的多个尺度上,我设法生成了以下图:
不过,我想在每个刻度中添加一个显示 y-max 值的刻度,而不考虑它与前一个刻度之间的差距。此类图的示例如下所示。它在 y-max 是滴答间隔的倍数时产生。
谢谢,F.
这是用于生成这些示例的代码。
import numpy as np
import pylab as pl
import matplotlib as plt
import matplotlib.ticker as ticker
import matplotlib.transforms
def add_scales(fig, axes, scales, subplot_reduction_factor=0.1, margin_size=50):
nb_scales = len(scales)
b,l,w,h = zoom_ax.get_position().bounds
_, ymax = axes.get_ylim()
# Saves some space to the right so that we can add our scales
fig.subplots_adjust(right=1-(subplot_reduction_factor)*nb_scales)
for (n, (vmin, vmax, color, label, alignment)) in enumerate(scales):
# Adjust wrt. the orignial figure's scale
nax = fig_zoom.add_axes((b,l,w,(h * alignment) / ymax))
nax.spines['right'].set_position(('outward', -40+n*margin_size))
nax.set_ylim((vmin,vmax))
# Move ticks and label to the right
nax.yaxis.set_label_position('right')
nax.yaxis.set_ticks_position('right')
# Hides everything except yaxis
nax.patch.set_visible(False)
nax.xaxis.set_visible(False)
nax.yaxis.set_visible(True)
nax.spines["top"].set_visible(False)
nax.spines["bottom"].set_visible(False)
# Color stuff
nax.spines['right'].set_color(color)
nax.tick_params(axis='y', colors=color)
nax.yaxis.set_smart_bounds(False)
#nax.yaxis.label.set_color(color)
if label != None:
nax.set_ylabel(None)
if __name__ == '__main__':
a=(np.random.normal(10,5,100))
a=np.linspace(0,100,100)
c=np.linspace(0,80, 100)
d=np.linspace(0,40,100)
fig_zoom = plt.pyplot.figure()
zoom_ax = fig_zoom.add_subplot(1,1,1)
zoom_ax.plot(a,c)
zoom_ax.plot(a,d)
zoom_ax.set_title('Zoom')
zoom_ax.set_xlabel('A')
zoom_ax.set_ylabel('B')
zoom_ax.set_ylim((0,100))
zoom_ax.grid()
add_scales(fig_zoom,
zoom_ax, [(0,.55,'green',None,40),
(0,.85,'blue',None,80)])
fig_zoom.savefig(open('./test.svg','w'),format='svg')
最佳答案
您可以将最高 ytick 值设置为最大值。如果第二高的 ytick 值和您的最大值非常接近,标签可能会困惑。
尝试将此添加到您的循环中:
tcks = nax.get_yticks()
tcks[-1] = vmax
nax.set_yticks(tcks)
关于python - Matplotlib 添加一个特定的刻度表示轴最大值 - 多尺度单次观察,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15291032/
我的代码中有一个 ggplot2 绘图函数。当文件作为 R 代码来源时,该函数工作正常,但是当我将此函数包含在 R 包中时(当然,我在包的描述和命名空间文件中包含 ggplot2 和比例),我得到以下
VINS中的重力-尺度-速度初始化(2) 细化重力 \(\quad\) 上一篇文章中得到的 \(g\) 一般是存在误差的。因为在实际应用中,当地的重力向量的模一般是已知固定大小的(所以只有
我正在使用 perl 脚本解析一些天气数据,然后使用 gnuplot 在 3 行 2 列显示中绘制这些数据。除了最后一张图“累积降雨量”之外,我的所有图表似乎都可以正常工作。该图实际上绘制正确,但 y
我有两组数据,我想用条形图绘制。但问题是这两组数据的规模截然不同。如果我只使用 bar(A),它看起来像这样:分组但第二个数据集几乎不可见,因为比例。 但是,如果我使用 plotyy(x,y1,x,y
考虑以下用于绘制 matplotlib 图的 python 代码: import matplotlib.pylab as pp import numpy as np alpha = np.linspa
在调查 ConflictError ( see this previous question ) 时,我看到了很多 persistent.mapping.PersistentMapping 冲突。 具
我正在阅读一些代码,其中我注意到使用pyplot.xaxis('log')和pyplot.yaxis('log')时发生了很大的变化。所以基本的散点图如下所示: 添加后: plt.xscale('lo
当覆盖具有相同长度但不同尺度数据的 ggplot 密度图时,是否可以对图的 x 尺度进行归一化以使密度匹配?或者有没有办法标准化密度 y 尺度? library(ggplot2) data <- da
如何在 pyqtgraph 中生成具有两个 Y 尺度的图? 我还需要两个不同颜色的(对应于线条的颜色)。 在 matplotlib 中,可以使用 twinx 来完成,如this example . 如
我有一个看起来像这样的表 我将突出显示的部分作为矩阵,我想对其执行 imshow。我想让绘图的 x 尺度为对数,通过查看最上面一行的参数值可以理解这一点。 matplotlib 是怎么做到的? 最佳答
我正在使用 nvd3 绘制一些系列,并想在绘图中添加一些任意矩形。我如何访问 d3 图的底层 x 和 y 比例,以便我可以将我的矩形坐标转换为 svg 像素坐标,以便与现有数据具有相同的比例: fun
我是一名优秀的程序员,十分优秀!