2
I would like to know how I change my x-axis from a graph with two y-axes, because I want to give the x-axis names of Brazilian states.
numpy_matrix = df.as_matrix()
x = numpy_matrix[0:,0]
y1 = numpy_matrix[1:,1]
y2 = numpy_matrix[2:,2]
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x, y1, 'r--')
ax2.plot(x, y2, 'b-')
Being the x, the states names and Y1 and Y2 the values. However, this form of error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-134-e3b753bdf6d4> in <module>()
1 fig, ax1 = plt.subplots()
2 ax2 = ax1.twinx()
----> 3 ax1.plot(x, y1, 'r--')
4 ax2.plot(x, y2, 'b-')
~\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1853 "the Matplotlib list!)" % (label_namer, func.__name__),
1854 RuntimeWarning, stacklevel=2)
-> 1855 return func(ax, *args, **kwargs)
1856
1857 inner.__doc__ = _add_data_doc(inner.__doc__,
~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs)
1525 kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
1526
-> 1527 for line in self._get_lines(*args, **kwargs):
1528 self.add_line(line)
1529 lines.append(line)
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs)
404 this += args[0],
405 args = args[1:]
--> 406 for seg in self._plot_args(this, kwargs):
407 yield seg
408
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
381 x, y = index_of(tup[-1])
382
--> 383 x, y = self._xy_from_xy(x, y)
384
385 if self.command == 'plot':
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
240 if x.shape[0] != y.shape[0]:
241 raise ValueError("x and y must have same first dimension, but "
--> 242 "have shapes {} and {}".format(x.shape, y.shape))
243 if x.ndim > 2 or y.ndim > 2:
244 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (22,) and (21,)
If I do:
ax1.plot(y1, 'r--')
ax2.plot(y2, 'b-')
Sure, but the x-axis gets random values.
I would like to know what to do to change the values of the x-axis to the names of the states I am working on.
Grateful.