在Y键之间添加间距

发布于 2025-01-18 03:26:49 字数 1509 浏览 1 评论 0原文

因此,我正在创建多条线,但多个 y 轴刻度线彼此重叠。那么是否有任何堆叠或不同的方法,以便可以查看所有刻度线是否可见并能够绘制出来。如果有人有任何解决方案,请帮助我。提前致谢。

from pylab import *
from scipy.interpolate import make_interp_spline
from matplotlib.pyplot import margins
from matplotlib.pyplot import figure
import matplotlib as mpl
from matplotlib.colors import LinearSegmentedColormap
from matplotlib import colors

plt.rcParams['figure.dpi'] = 300
plt.rcParams["figure.figsize"] = (35,40)
col = ['purple', 'green' , 'yellow']
position = []
position_1 = []

val = am.columns
val = val.insert(0,'Week 0')
xs = np.arange(len(val))

plt.xticks(xs, val)
plt.xticks(fontsize=35)

a = colors.to_rgb(col[0]) 
b = colors.to_rgb(col[1]) 
c = colors.to_rgb(col[2])
color = [a, b, c]
cm = LinearSegmentedColormap.from_list("Custom", color, N=len(am))
k = 0

frst = am['Week 1'].values
frst.sort()

color_list = [cm(i) for i in range(11)]

c_dict = dict(zip(frst, color_list))

for k in range(len(am)):
  x= np.arange(1,6)
  y = am.iloc[k].values
  colrs = c_dict[y[0]]
  position.append(y[0])
  position_1.append(y[-1] - 10)
  
  X_Y_Spline = make_interp_spline(x, y)
  
  x = np.linspace(x.min(), x.max(), 300)
  y = X_Y_Spline(x)

  for i in range(len(x)-1):
      plt.plot(x[i:i+2], y[i:i+2], linewidth=y[i]/5, color=colrs)
      
margins(0)
plt.yticks(position, am.index.values)
plt.yticks(fontsize=35)
plt.twinx()
plt.yticks(position_1, am.index.values)
plt.yticks(fontsize=35)
plt.show()

在此处输入图像描述

So I am creating a multiple line but multiple y-axis ticks are overlapping each other. So is there any stacked or different approach so can view all the ticks are visible and able to plot that. Please help me if anyone has any solution. Thanks in advance.

from pylab import *
from scipy.interpolate import make_interp_spline
from matplotlib.pyplot import margins
from matplotlib.pyplot import figure
import matplotlib as mpl
from matplotlib.colors import LinearSegmentedColormap
from matplotlib import colors

plt.rcParams['figure.dpi'] = 300
plt.rcParams["figure.figsize"] = (35,40)
col = ['purple', 'green' , 'yellow']
position = []
position_1 = []

val = am.columns
val = val.insert(0,'Week 0')
xs = np.arange(len(val))

plt.xticks(xs, val)
plt.xticks(fontsize=35)

a = colors.to_rgb(col[0]) 
b = colors.to_rgb(col[1]) 
c = colors.to_rgb(col[2])
color = [a, b, c]
cm = LinearSegmentedColormap.from_list("Custom", color, N=len(am))
k = 0

frst = am['Week 1'].values
frst.sort()

color_list = [cm(i) for i in range(11)]

c_dict = dict(zip(frst, color_list))

for k in range(len(am)):
  x= np.arange(1,6)
  y = am.iloc[k].values
  colrs = c_dict[y[0]]
  position.append(y[0])
  position_1.append(y[-1] - 10)
  
  X_Y_Spline = make_interp_spline(x, y)
  
  x = np.linspace(x.min(), x.max(), 300)
  y = X_Y_Spline(x)

  for i in range(len(x)-1):
      plt.plot(x[i:i+2], y[i:i+2], linewidth=y[i]/5, color=colrs)
      
margins(0)
plt.yticks(position, am.index.values)
plt.yticks(fontsize=35)
plt.twinx()
plt.yticks(position_1, am.index.values)
plt.yticks(fontsize=35)
plt.show()

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文