Coder 477
Coder 477

Reputation: 435

Scaling axis for a scatter plot in matlibplot in python

I am working with data visualization using matlibplot. My plot has a total of 6502 data values and is working fine, but the values are close and dense.

For example my y axis values ranges between 3 and 10 and I need to get each point between them so clearly. i.e values like 9.2 and 9.8 are to be clearly distinguished with at least a scale of 1=0.5. i.e all values like 3,3.5,4,4.5...10,10.5 are all seen in the output figure

Can some one explain me how it can be done. I tired setting range using max and min values. but it didn't work. I set the limits from 3.5 to 10.5 but in the figure the axes are displayed with scaling of 1=1 and values are from 4 to 10. Please help me fix this issue

Thanks in advance

here's my code so far

 import matplotlib.pyplot as plt
 import numpy as np
 import plotly.plotly as py

 c, ec = np.random.rand(2, len(votes), 10)
 fig, ax = plt.subplots()
 plt.ylim(3.5, 10.5)
 plt.grid(True)
 # where votes range from 10-1000000 and rank range from 3.5 to 10
 matplotlib.pyplot.scatter(votes,rank, c=c, edgecolor=ec)
 plot_url = py.plot_mpl(fig, filename='scatter-plot')
 matplotlib.pyplot.show()

and my plot is here

scatter-plot

Upvotes: 3

Views: 37336

Answers (1)

Kirubaharan J
Kirubaharan J

Reputation: 2365

use plt.yticks(np.arange(min, max, step)) instead of plt.ylim()

Upvotes: 8

Related Questions