回答編集履歴

2

質問追加に対する回答追加

2021/03/21 14:09

投稿

ppaul
ppaul

スコア24666

test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  `~matplotlib.ticker.LinearLocator`.
28
28
 
29
-
29
+ ![グラフ](d5d69dc0dbafa075e6733010c6925720.png)
30
30
 
31
31
  Returns
32
32
 
@@ -47,3 +47,109 @@
47
47
  events are only called for the artists in the top-most axes.
48
48
 
49
49
  ```
50
+
51
+
52
+
53
+ ラベルとか手抜きなので追加して下さい。
54
+
55
+
56
+
57
+ 仮データ作成
58
+
59
+ ```python
60
+
61
+ import pandas as pd
62
+
63
+ import io
64
+
65
+
66
+
67
+ indata1 = '''日付け 終値
68
+
69
+ 2020-03-02 1015
70
+
71
+ 2020-03-03 1025
72
+
73
+ 2020-03-04 1050
74
+
75
+ 2020-03-05 999
76
+
77
+ 2020-03-06 1080'''
78
+
79
+
80
+
81
+ with io.StringIO(indata1) as f:
82
+
83
+ df1 = pd.read_csv(f, sep=' +', engine='python', parse_dates=[0])
84
+
85
+
86
+
87
+ indata2 = '''日付け 終値
88
+
89
+ 2020-03-02 3056
90
+
91
+ 2020-03-03 3523
92
+
93
+ 2020-03-04 4024
94
+
95
+ 2020-03-05 5095
96
+
97
+ 2020-03-06 3800'''
98
+
99
+
100
+
101
+ with io.StringIO(indata2) as f:
102
+
103
+ df2 = pd.read_csv(f, sep=' +', engine='python', parse_dates=[0])
104
+
105
+ ```
106
+
107
+
108
+
109
+ 表示コード
110
+
111
+ ```python
112
+
113
+ import pandas as pd
114
+
115
+ import datetime
116
+
117
+ import matplotlib.pyplot as plt
118
+
119
+ import matplotlib.dates as mdates
120
+
121
+ import numpy as np
122
+
123
+
124
+
125
+ Date = df1["日付け"].values.astype(np.datetime64)
126
+
127
+ EP1 = df1['終値'].values
128
+
129
+ EP2 = df2['終値'].values
130
+
131
+
132
+
133
+ fig = plt.figure(figsize=(30,10))
134
+
135
+ ax = fig.add_subplot(111)
136
+
137
+ ax.plot(Date, EP1,'C0')
138
+
139
+ ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
140
+
141
+ ax2 = ax.twinx()
142
+
143
+ ax2.plot(Date, EP2,'C1')
144
+
145
+ ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
146
+
147
+ plt.show()
148
+
149
+ ```
150
+
151
+ 実行結果
152
+
153
+
154
+
155
+ ![イメージ説明](182f49caef778a0e3bb93fa2d7915033.png)

1

コード追加

2021/03/21 14:09

投稿

ppaul
ppaul

スコア24666

test CHANGED
@@ -3,3 +3,47 @@
3
3
 
4
4
 
5
5
  が同じx軸を使うグラフを作っています。
6
+
7
+
8
+
9
+ ```python
10
+
11
+ >>> print(ax1.twinx.__doc__)
12
+
13
+
14
+
15
+ Create a twin Axes sharing the xaxis.
16
+
17
+
18
+
19
+ Create a new Axes with an invisible x-axis and an independent
20
+
21
+ y-axis positioned opposite to the original one (i.e. at right). The
22
+
23
+ x-axis autoscale setting will be inherited from the original
24
+
25
+ Axes. To ensure that the tick marks of both y-axes align, see
26
+
27
+ `~matplotlib.ticker.LinearLocator`.
28
+
29
+
30
+
31
+ Returns
32
+
33
+ -------
34
+
35
+ ax_twin : Axes
36
+
37
+ The newly created Axes instance
38
+
39
+
40
+
41
+ Notes
42
+
43
+ -----
44
+
45
+ For those who are 'picking' artists while using twinx, pick
46
+
47
+ events are only called for the artists in the top-most axes.
48
+
49
+ ```