Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 262
Coder 477 Avatar asked Feb 23 '26 00:02

Coder 477


1 Answers

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

like image 119
Kirubaharan J Avatar answered Feb 25 '26 13:02

Kirubaharan J