Jin*_*Jin 5 python plot matplotlib
我想要手动覆盖 y 轴刻度标签而不影响原始绘图。\n例如,如何显示 y 轴刻度标签 [1,10,100,1000,10000] 而不会影响原始绘图形状,即仍然显示完美的二次曲线。
\n\nimport numpy as np\nimport pylab as pl\nx = [1, 2, 3, 4, 5]\ny = [1, 4, 9, 16, 25]\npl.plot(x, y)\npl.title(\xe2\x80\x99Plot of y vs. x\xe2\x80\x99)\npl.xlabel(\xe2\x80\x99x axis\xe2\x80\x99)\npl.ylabel(\xe2\x80\x99y axis\xe2\x80\x99)\npl.show()\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试了以下方法但不起作用
\n\nnewYlabel = ['1','10','100','1000','10000']\np1.set_yticklabels(newYlabel)\nRun Code Online (Sandbox Code Playgroud)\n
set_yticklabels是实例的方法Axes,接口中不存在pylab。尝试一下
pl.gca().set_yticklabels(newYlabel)
Run Code Online (Sandbox Code Playgroud)
gca这里代表获取当前轴。
编辑:图片:

用于获取它的脚本:
import numpy as np
import pylab as pl
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
pl.plot(x, y)
pl.title('Plot of y vs. x')
pl.xlabel('x axis')
pl.ylabel('y axis')
newYlabel = ['1','10','100','1000','10000']
pl.gca().set_yticklabels(newYlabel)
pl.show()
Run Code Online (Sandbox Code Playgroud)
在 Fedora 21 上使用 matplotlib 1.4.3 和 python 2.7.8。
| 归档时间: |
|
| 查看次数: |
4060 次 |
| 最近记录: |