1

enter image description here

I have obtained this image via matplotlib library.

Now I just want to increase y axis length to get a clearer view.

Code is given below:

plt.figure(1)
plt.subplot(211)
plt.plot_date(df['Condition'],df['Date'], tz=None, xdate=True, ydate=False)
plt.title('Scatter plot')
plt.xlabel('Condition')
plt.ylabel('Date')
plt.show()
Harshil Shah
  • 142
  • 2
  • 3
  • 13

2 Answers2

2

You need to change the figure size. This can be controlled with feeding a tuple to the figsize keyword argument provided to plt.figure:

import matplotlib.pyplot as plt
plt.figure(1, figsize=(4, 6)) # Figure size in inches (size_x, size_y)
plt.subplot(211)
# plt.plot_date(df['Condition'],df['Date'], tz=None, xdate=True, ydate=False)
plt.title('Scatter plot')
plt.xlabel('Condition')
plt.ylabel('Date')
plt.show()

The above lines create the following figure:

Leonard
  • 2,510
  • 18
  • 37
1

This should answer your question.

axes = plt.gca()

axes.set_xlim([xmin,xmax])

axes.set_ylim([ymin,ymax])

H. Farrow
  • 21
  • 3
  • Date on y axis is dynamic. How can I find min and max date from that? – Harshil Shah Jun 06 '19 at 05:39
  • This might be helpful. If you are trying to limit the x-axis so that it ranges from a static minimum to a dynamic maximum, with the max being the largest datetime object in your dataset, try # ... plt.xlim( xmin=datetime.datetime(2017, 1, 4, hour=13), # the one that doesn't change xmax=max(x) # the latest datetime in your dataset ) – H. Farrow Jun 06 '19 at 05:51
  • 1
    -1: OP's image and question show clearly they want the plotting area to be bigger, not a change in visualization bounds (which this achieves). – Leporello Jun 06 '19 at 09:20