如何设置半长轴

2024-04-26 14:07:42 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我想法的例证。在一个图形中绘制三个属性

我想设置我的轴系统像下面的风格。顶部轴的范围为0-1;底轴范围为-1~1

有没有办法做到这一点

+------+             ---+ 
|      |         
|      |   --->  
|      |         
+------+         +-------

Tags: 图形属性风格系统绘制办法底轴
1条回答
网友
1楼 · 发布于 2024-04-26 14:07:42

一个可以将两个轴放在彼此的顶部,一个轴的宽度是另一个轴的一半。然后设置轴脊椎不可见,并调整轴的限制,一个类似于问题中的一个绘图产生

enter image description here

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(6,3))
ax1 = fig.add_axes([0.1,0.1, 0.35,0.8])
ax2 = fig.add_axes([0.55,0.1, 0.35,0.8])
ax3 = fig.add_axes([0.55+0.175,0.1, 0.175,0.8], facecolor=(0,0,0,0))
ax3.xaxis.tick_top()
ax2.set_xlim([-1,1])
ax3.set_xlim([0,1])

ax2.spines['right'].set_color('none')
ax3.spines['right'].set_color('none')
ax2.spines['left'].set_color('none')
ax3.spines['left'].set_color('none')
ax2.spines['top'].set_color('none')
ax3.spines['bottom'].set_color('none')
ax2.set_yticks([])
ax3.set_yticks([])


x = np.linspace(-1,1,201)
f = lambda x,b: np.sin(x/b)
f2 = lambda x,a,b: ((x/b-a)*np.exp(-(x/b-a)**2))**2

ax1.plot(x, f(x,0.5)*f2(x,1,0.5),  color="C3")
ax2.plot(x,f2(x, -1.8,0.5),  color="C1")
ax3.plot(x,f(x,0.1), color="C2")

ax3.set_ylim([-3,1.5])

plt.show()

相关问题 更多 >