title: 2 line-plots in same visualization with different y-axis
body: <p>I am quite stuck with this one.
  I am trying to create a line diagram with the same x-axis scale (years) but a different y-axis scale
  How can I do that?</p>
  <p>I have two datasets with this info:</p>
  <pre><code>test_data1.head()
     latitude longitude   place       year
  0   36.087  -106.168    New Mexico  1973
  1   33.917  -90.775     Mississippi 1973
  2   37.160  -104.594    Colorado    1973
  3   37.148  -104.571    Colorado    1973
  4   36.500  -100.693    Oklahoma    1974
  
  test_data2.head()
      LAT          LONG       BBLS    Year
  0   36.900324   -98.21826   300     1977.0
  1   36.896636   -98.17772   1,000   2002.0
  2   36.806113   -98.32584   1,000   1988.0
  3   36.888589   -98.31853   1,000   1985.0
  4   36.892128   -98.19462   2,400   2002.0
  </code></pre>
  <p>for context, test_data1 refers to earthquakes and test_data2 refers to injection wells and BBLS is the number of barrels produced.</p>
  <p>What I want to do is create a line diagram showing the number of earthquakes per year, and the number of barrels produced per year from 1980. I want to display the number of earthquakes per year on the left (y1) and the number of barrels produced per year on the right (y2).</p>
  <p>Here's what I've done but it didn't work, anyone knows why or show me a way to do it?</p>
  <pre><code>import matplotlib.pyplot as plt
  from pandas.plotting import register_matplotlib_converters
  register_matplotlib_converters()
  %matplotlib  inline 
  
  x=test_data1['year']
  y1 = test_data1['place']
  y2 = test_data2['BBLS']
  
  fig, ax1 = plt.subplots()
  ax2 = ax1.twinx()
  curve1 = ax1.plot (x, y1, label='Number of Earthquakes', color='r')
  curve2= ax2.plot (x, y2, label='Number of Barrels Produced', color='b')
  plt.plot()
  plt.show()
  </code></pre>
  <p>I'm getting this huge error but I can't understand it since I am new to Python:</p>
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-109-9e26d5f7e5e2&gt; in &lt;module&gt;
       11 ax2 = ax1.twinx()
       12 curve1 = ax1.plot (x, y1, label='Number of Earthquakes', color='r')
  ---&gt; 13 curve2= ax2.plot (x, y2, label='Number of Barrels Produced', color='b')
       14 plt.plot()
       15 plt.show()
  
  ~\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
     1741         &quot;&quot;&quot;
     1742         kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
  -&gt; 1743         lines = [*self._get_lines(*args, data=data, **kwargs)]
     1744         for line in lines:
     1745             self.add_line(line)
  
  ~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in __call__(self, data, *args, **kwargs)
      271                 this += args[0],
      272                 args = args[1:]
  --&gt; 273             yield from self._plot_args(this, kwargs)
      274 
      275     def get_next_color(self):
  
  ~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
      394             self.axes.xaxis.update_units(x)
      395         if self.axes.yaxis is not None:
  --&gt; 396             self.axes.yaxis.update_units(y)
      397 
      398         if x.shape[0] != y.shape[0]:
  
  ~\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data)
     1461         neednew = self.converter != converter
     1462         self.converter = converter
  -&gt; 1463         default = self.converter.default_units(data, self)
     1464         if default is not None and self.units is None:
     1465             self.set_units(default)
  
  ~\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis)
      105         # the conversion call stack is default_units -&gt; axis_info -&gt; convert
      106         if axis.units is None:
  --&gt; 107             axis.set_units(UnitData(data))
      108         else:
      109             axis.units.update(data)
  
  ~\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data)
      174         self._counter = itertools.count()
      175         if data is not None:
  --&gt; 176             self.update(data)
      177 
      178     @staticmethod
  
  ~\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data)
      209         for val in OrderedDict.fromkeys(data):
      210             # OrderedDict just iterates over unique values in data.
  --&gt; 211             cbook._check_isinstance((str, bytes), value=val)
      212             if convertible:
      213                 # this will only be called so long as convertible is True.
  
  ~\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in _check_isinstance(_types, **kwargs)
     2244     for k, v in kwargs.items():
     2245         if not isinstance(v, types):
  -&gt; 2246             raise TypeError(
     2247                 &quot;{!r} must be an instance of {}, not a {}&quot;.format(
     2248                     k,
  
  TypeError: 'value' must be an instance of str or bytes, not a float
  </code></pre>
  <p>Still, Jupiter produces some plot which ofc isn't what I am looking for, not to mention that I am obtaining the y1 in terms of place but I do want just to count the number of earthquakes in a year, I just felt that using the 'place' would make the code just to count.
  Please, help.</p>
  <p><a href="https://i.stack.imgur.com/6FbmS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6FbmS.png" alt="enter image description here" /></a></p>
  <p>Here are the datasets I am working on in case it's useful. Note that they have many more columns but I am not using them as they aren't relevant for this graphic.</p>
  <p><a href="https://drive.google.com/file/d/1FFFKmmla14AXRVuZJd53oD3fULapob7F/view?usp=sharing" rel="nofollow noreferrer">okQuakes.csv</a> (test_data1)
  <a href="https://drive.google.com/file/d/1F79iKrXQTLGIaiRhdl5GXtqPMpcqcoAP/view?usp=sharing" rel="nofollow noreferrer">InjectionWells.csv</a> (test_data2)</p>