英文:
How can add max and mix value at the y axis?
问题
以下是已翻译的内容:
在`df['close']`中的最大和最小值:
pmax,pmin = max(df['close']), min(df['close'])
pmax,pmin
(35.48, 19.37)
在y轴上不包含最大和最小值的图形:
pmax,pmin = max(df['close']), min(df['close'])
fig, ax = plt.subplots()
ax.plot(df.index, df['close'])
ax.set_ylim(pmin, pmax)
绘制y轴上包含最大和最小值但没有中间刻度的图形:
pmax,pmin = max(df['close']), min(df['close'])
fig, ax = plt.subplots()
ax.plot(df.index, df['close'])
ax.set_yticks([pmin, pmax])
ax.set_ylim(pmin, pmax)
请注意,图片和链接不包括在翻译中。
英文:
The max and min value in the df['close']
:
pmax,pmin = max(df['close']),min(df['close'])
pmax,pmin
(35.48, 19.37)
Draw the graph without max and min value at the y axis:
pmax,pmin = max(df['close']),min(df['close'])
fig, ax = plt.subplots()
ax.plot(df.index,df['close'])
ax.set_ylim(pmin, pmax)
Draw the graph with max and min value at the y axis,but no middle ticks in the y axis:
pmax,pmin = max(df['close']),min(df['close'])
fig, ax = plt.subplots()
ax.plot(df.index,df['close'])
ax.set_yticks([pmin,pmax])
ax.set_ylim(pmin, pmax)
答案1
得分: 1
你可以使用 ax.get_yticks()
获取当前的 y轴刻度值,然后将特定的值(pmin, pmax)添加到这些刻度值中,然后使用 ax.set_yticks()
来设置它们。下面的示例使用随机值演示了如何实现这一操作。
df = pd.DataFrame({'close': np.random.uniform(19, 36, 200)})
pmax, pmin = max(df['close']), min(df['close'])
fig, ax = plt.subplots(figsize=(12, 5))
ax.plot(df.index, df['close'])
ax.set_ylim(pmin, pmax)
ticks = np.append(ax.get_yticks(), [pmin, pmax])
ax.set_yticks(ticks)
英文:
You can add the specific values (pmin, pmax) to the yticks() using the ax.get_yticks()
, adding the two values and then using ax.set_yticks()
to set it. The example below with random values should show you how to achieve this.
df=pd.DataFrame({'close':np.random.uniform(19, 36, 200)})
pmax,pmin = max(df['close']),min(df['close'])
fig, ax = plt.subplots(figsize=(12,5))
ax.plot(df.index,df['close'])
ax.set_ylim(pmin, pmax)
ticks = np.append(ax.get_yticks(), [pmin,pmax])
ax.set_yticks(ticks)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论