![](/img/trans.png)
[英]How to get the desired labels on ticks on the x-axis in a matplotlib plot?
[英]Matplotlib: How to add another X-axis where the ticks correspond to the points on the graph with custom labels
我想从一个脚本中获取 plot 数据。 我的代码是这样的:
f, ax = plt.subplots()
a = [10, 20, 30] # N Total Items
b = [1, 5, 10] # Time (s)
c = [2, 6, 7] # N items of lenght 1
ax.plot(a, b, '-m^')
ax2 = ax.twiny()
ax2.set_xticks(ax.get_xticks())
ax2.set_xticklabels(c)
ax.set_xlabel("N Total Items")
ax.set_ylabel("Time (s)")
ax2.set_xlabel("N items of lenght 1")
我希望 C 值表示对应于图表上绘制的每个点的刻度。 因此,“2”对应点 (10, 1),“6”对应点 (20, 5),依此类推。
有什么方法可以通过 matplotlib 实现这一目标? 先感谢您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.