3

I want to plot some Data with Matplotlib scatter plot. I used the following code to plot the Data as a scatter with using the same axes for the different subplots.

import numpy as np
import matplotlib.pyplot as plt

epsilon= np.array([1,2,3,4,5])

f, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex= True, sharey=True)
ax1.scatter(epsilon, mean_percent_100_0, color='r', label='Totaldehnung= 0.000')
ax1.scatter(epsilon, mean_percent_100_03, color='g',label='Totaldehnung= 0.003')
ax1.scatter(epsilon, mean_percent_100_05, color='b',label='Totaldehnung= 0.005')
ax1.set_title('TOR_R')
ax2.scatter(epsilon, mean_percent_111_0,color='r')
ax2.scatter(epsilon, mean_percent_111_03,color='g')
ax2.scatter(epsilon, mean_percent_111_05,color='b')
ax3.scatter(epsilon, mean_percent_110_0,color='r')
ax3.scatter(epsilon, mean_percent_110_03,color='g')
ax3.scatter(epsilon, mean_percent_110_05,color='b')
ax4.scatter(epsilon, mean_percent_234_0,color='r')
ax4.scatter(epsilon, mean_percent_234_03,color='g')
ax4.scatter(epsilon, mean_percent_234_05,color='b')

# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0.13)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
plt.locator_params(axis = 'y', nbins = 4)

ax1.grid()
ax2.grid()
ax3.grid()
ax4.grid()

plt.show()

Now i want to have a x-axis with smaller space between each point. I tried to change the range but it was not working. Can someone help me? enter image description here

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
user3616531
  • 61
  • 1
  • 5
  • Do you just want your figure to be "narrower" overall? If so, you can use the `figsize` keyword argument in your `plt.subplots` command. If you don't just want your figure to be narrower, then you'll need to say a bit more about what you want. In particular, do you want extra whitespace to the left of your more-tightly-spaced x-axis, or to the right, or something else? – 8one6 Oct 13 '14 at 15:27
  • the distances between the 1,2,3... should be smaller, so yes a more-tightly-spaced x-axis. – user3616531 Oct 13 '14 at 19:13

1 Answers1

1

To make the x ticks come closer you might have to set the dimensions of the figure.

Since, in your case, the figure is already created, Set the size of the plot using set_size_inches method of the figure object.

This question contains a few other ways to do the same.

Adding the following line before the plt.show()

fig.set_size_inches(2,8)

Gives me this :

enter image description here

Which I hope is what you are trying to do.

Community
  • 1
  • 1
Raghav RV
  • 3,938
  • 2
  • 22
  • 27