Scaling axis for a scatter plot in matlibplot in python

坚强是说给别人听的谎言 提交于 2020-01-02 06:51:38

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/27456185/scaling-axis-for-a-scatter-plot-in-matlibplot-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!