Matplotlib:将原点移动到左上角
Matplotlib: move Origin to upper left corner
在Matlab中,绘制原点在左上角,x轴为原点南正,y轴为原点东; x 轴在左边距上编号,y 轴在上边距上标记。
figure();
set(gca,'YAxisLocation','Right','YDir','reverse')
axis([0 10 0 10]);
daspect([1,1,1])
grid on
view([-90 -90])
如何在 Python 中实现同样的效果?我是这样进行的:
import matplotlib.pyplot as plt
plt.figure(1)
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
python 等价于什么:
set(gca,'YAxisLocation','Right','YDir','reverse')
daspect([1,1,1])
view([-90 -90])
编辑:
figure
set(gca,'YAxisLocation','right','XTick',0:15,'YDir','reverse')
axis([0 16 0 16]);
daspect([1,1,1])
hold on
text(2,8,'CHN');
text(8,2,'USA');
view([-90 -90])
输出为:
这是一个注释示例,它显示了如何反转轴并将刻度移动到顶部、设置网格状态并模仿 view() 命令:
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
plt.axis([0, 16, 0, 16])
plt.grid(False) # set the grid
data= [(8,2,'USA'), (2,8,'CHN')]
for obj in data:
plt.text(obj[1],obj[0],obj[2]) # change x,y as there is no view() in mpl
ax=plt.gca() # get the axis
ax.set_ylim(ax.get_ylim()[::-1]) # invert the axis
ax.xaxis.tick_top() # and move the X-Axis
ax.yaxis.set_ticks(np.arange(0, 16, 1)) # set y-ticks
ax.yaxis.tick_left() # remove right y-Ticks
图片:
在Matlab中,绘制原点在左上角,x轴为原点南正,y轴为原点东; x 轴在左边距上编号,y 轴在上边距上标记。
figure();
set(gca,'YAxisLocation','Right','YDir','reverse')
axis([0 10 0 10]);
daspect([1,1,1])
grid on
view([-90 -90])
如何在 Python 中实现同样的效果?我是这样进行的:
import matplotlib.pyplot as plt
plt.figure(1)
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
python 等价于什么:
set(gca,'YAxisLocation','Right','YDir','reverse')
daspect([1,1,1])
view([-90 -90])
编辑:
figure
set(gca,'YAxisLocation','right','XTick',0:15,'YDir','reverse')
axis([0 16 0 16]);
daspect([1,1,1])
hold on
text(2,8,'CHN');
text(8,2,'USA');
view([-90 -90])
输出为:
这是一个注释示例,它显示了如何反转轴并将刻度移动到顶部、设置网格状态并模仿 view() 命令:
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
plt.axis([0, 16, 0, 16])
plt.grid(False) # set the grid
data= [(8,2,'USA'), (2,8,'CHN')]
for obj in data:
plt.text(obj[1],obj[0],obj[2]) # change x,y as there is no view() in mpl
ax=plt.gca() # get the axis
ax.set_ylim(ax.get_ylim()[::-1]) # invert the axis
ax.xaxis.tick_top() # and move the X-Axis
ax.yaxis.set_ticks(np.arange(0, 16, 1)) # set y-ticks
ax.yaxis.tick_left() # remove right y-Ticks
图片: