Pyplot / Matplotlib:如何实现压缩的y轴 [英] Pyplot / Matplotlib: How to achieve a compressed y-axis
问题描述
我正在使用pyplot根据Walter / Lieth的可视化效果创建一个气候记录仪。
)
I am using pyplot to create a climograph based on the visualization of Walter/Lieth.
Another Climograph by Walter/Lieth
As you can see on the images (the links above), the right y-axis is compressed starting from the value of 100. Their visual distance gets smaller while their numerical intervals become larger.
I can't figure out how to achieve this in pyplot. I know how to set the tick values to create a custom scale but of course they always are equidistant. As you can see in my plot the plotted space on the right y-axis corresponds to the interval of the values:
Maybe someone could give a hint on how to achieve the effect shown in the two links above.
Cheers!
An example for you:
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()
My example only shows how you can tweak the Y coordinate ticks, as you wanted to know. Sorry for not being too helpful apparently. I do not understand the downvote at all. There will probably be better answers, I guess.
For actual compression of the samples (data) there are a few ways:
Use a function to scale the data. Maybe defined in steps. i.e. for 0 < n < 10 leave it as it is, for 10 <= n <100 turn into 11~19, etc.
Use log scales ( https://matplotlib.org/examples/pylab_examples/log_demo.html )
这篇关于Pyplot / Matplotlib:如何实现压缩的y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!