簡體   English   中英

Matplotlib pyplot粉碎梯子python

[英]Matplotlib pyplot crush a ladder python

我有以下示例數據(我僅報告幾行):

          date   price  sentiment
0   2018-09-18  0.0034   0.250000
1   2018-09-17  0.0034   0.083333
2   2018-09-16  0.0034   0.281250
3   2018-09-15  0.0035   0.096774
4   2018-09-14  0.0036  -0.039216
5   2018-09-13  0.0034   0.416667
6   2018-09-12  0.0031   0.061224

我的代碼示例是這樣的:

import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt

df = df.set_index(pd.to_datetime(df.date), drop=True)

params = {"text.color" : "black",
          'figure.figsize': (13, 5),
          "xtick.color" : "crimson",
          "ytick.color" : "crimson"}

plt.rcParams.update(params)
fig = plt.figure()

df.price.plot(grid=True, label="Price", legend=True, color='#228B22', title='Price vs Sentiment')
df.sentiment.plot(grid=True, secondary_y=True, label="Sentiment", legend=True, color='#3D59AB')

plt.show()

我想破壞情節中的情感線,以便更好地了解變化,也許顯示情感的整個范圍[-1; 1]。 有什么建議么? 我如何改善下面的情節?

情緒與價格走勢

如果要將情感軸從-1設為1,請執行此操作

import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt

df = pd.DataFrame({'date': ['2018-09-18', '2018-09-17', '2018-09-16', '2018-09-15', '2018-09-14', '2018-09-13', '2018-09-12'], 
               'price': [0.0034, 0.0034, 0.0034, 0.0035, 0.0036, 0.0034, 0.0031], 
               'sentiment': [0.25, 0.083333, 0.281250, 0.096774, -0.039216, 0.416667, 0.061224]})
df = df.set_index(pd.to_datetime(df.date), drop=True)

params = {"text.color" : "black",
      'figure.figsize': (13, 5),
      "xtick.color" : "crimson",
      "ytick.color" : "crimson"}

plt.rcParams.update(params)
fig = plt.figure()
df.price.plot(grid=True, label="Price", legend=True, color='#228B22', title='Price vs Sentiment')
df.sentiment.plot(grid=True, secondary_y=True, label="Sentiment", legend=True, color='#3D59AB', ylim=(-1, 1))
plt.show()

https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.DataFrame.plot.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM