如何在y轴上添加最大和最小值?

huangapple go评论71阅读模式
英文:

How can add max and mix value at the y axis?

问题

以下是已翻译的内容:

`df['close']`中的最大和最小值

pmaxpmin = max(df['close']), min(df['close'])
pmaxpmin
(35.48, 19.37)

在y轴上不包含最大和最小值的图形

pmaxpmin = max(df['close']), min(df['close'])
fig, ax = plt.subplots()
ax.plot(df.index, df['close'])
ax.set_ylim(pmin, pmax)

绘制y轴上包含最大和最小值但没有中间刻度的图形

pmaxpmin = 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)

如何在y轴上添加最大和最小值?

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)

如何在y轴上添加最大和最小值?

How can get the below graph?
如何在y轴上添加最大和最小值?

答案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)

如何在y轴上添加最大和最小值?

英文:

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)

如何在y轴上添加最大和最小值?

huangapple
  • 本文由 发表于 2023年7月3日 21:20:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定