我正在使用拟图来创建一个基于Walter/Lieth可视化的剪贴画。
正如你在图片上看到的(上面的链接),从100开始,右y轴被压缩。他们的视觉距离变得越来越小,而他们的数值间隔变得更大。
我想不出如何在拟图中实现这一点。我知道如何设置滴答值来创建自定义刻度,但当然它们总是等距的。正如您在我的图中所看到的,右边y轴上绘制的空间对应于值的间隔:

也许有人可以提示一下如何实现上述两个链接中所显示的效果。
干杯!
发布于 2018-05-10 21:59:58
给你举个例子:
import matplotlib.pyplot as plt
axes = plt.axes()
axes.set_xlim([-10, 10]) #whatever, optional
axes.set_ylim([0, 1.0]) # whatever, optional
axes.set_xticks([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5])
axes.set_yticks([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,150,200,300])
plt.plot(x, norm.pdf(x)) #random filler
plt.plot(x, norm.pdf(x, 70.0, 0.1)) #another absolutely random filler
plt.show()我的例子只显示了如何调整Y坐标滴答,正如您想知道的那样。很抱歉显然没能帮上忙。我一点也不明白否决的原因。我想可能会有更好的答案。
对于实际的样本(数据)压缩,有几种方法:
发布于 2018-05-11 14:53:33
“任择议定书”所作的答复,排除了他们的问题:
这里的解决方案是一个基于Attersons答案的解决方案的示例。标度函数取自这应答。
from matplotlib import pyplot as plt
def scale(val, src, dst):
"""
Scale the given value from the scale of src to the scale of dst.
"""
return ((val - src[0]) / (src[1]-src[0])) * (dst[1]-dst[0]) + dst[0]
# Actual data
data = [20, 50, 100, 250, 600, 200, 150, 100, 40, 30, 25, 20]
source_scale = (100, 600) # Scale values between 100 and 600
destination_scale = (100, 150) # to a scale between 100 and 150
# Apply scale to all items of data that are above or equal to 100
data_scaled = [x if x < 100 else scale(x, source_scale, destination_scale) for x in data]
# Set up a simple plot
fig = plt.figure()
ax = plt.Axes(fig, [0.,0.,1.,1.])
fig.add_axes(ax)
# Set the y-ticks to a custom scale
ax.set_yticks([0,20,40,60,80,100,110,120,130,140,150])
ax.set_ylim(0, 150)
# Set the labels to the actual values
ax.set_yticklabels(["0","20","40","60","80","100","200","300","400","500","600"])
ax.plot(data_scaled)

https://stackoverflow.com/questions/50282054
复制相似问题