Euphe - 11 months ago 70

Python Question

I am plotting 2 lines and a dot, X axis is a date range. The dot is most important, but it appears on the boundary of the plot. I want to "expand" the plot further right so that the dot position is more visible.

In other words I want to expand the X axis without adding new values to Y values of lines. However if I just add a few dates to X values of lines I get the "x and y dimensions must be equal" error. I tried to add a few np.NaN values to Y so that dimensions are equal, but then I get an error "integer required".

My plot:

My code:

`fig1 = plt.figure()`

ax1 = fig1.add_subplot(111)

plot_x = train_original.index.values

train_y = train_original.values

ax1.plot(plot_x, train_y, 'grey')

x = np.concatenate([np.array([train_original.index.values[-1]]), test_original.index.values])

y = np.concatenate([np.array([train_original.dropna().values[-1]]), test_original.dropna().values])

ax1.plot(x, y, color='grey')

ax1.plot(list(predicted.index.values), list(predicted.values), 'ro')

ax1.axvline(x=train_end, alpha=0.7, linestyle='--',color='blue')

plt.show()

Answer Source

Just change the xlim(). Something like:

```
xmin, xmax = plt.xlim() # return the current xlim
plt.xlim(xmax=xmax+1)
```