0

I am scratching my head in confusion as I am trying to give better aesthetics to the following plot.

enter image description here

import random

my_randoms = [random.randint(0,50) for p in range(600)]
my_randoms += [random.randint(50,1000) for p in range(300)]

bins = range(0, 1000, 50)
plt.hist(my_randoms, bins)
plt.xticks(bins)`enter code here`
plt.yticks(range(0, 500, 50))
plt.grid()
plt.show()

The problem is that i want to set the y axis tick in an non equal way e.g 0, 10,20, 30, 40, 50, 500 but with the same size and no breaking axes.

UPDATE

An awesome drawing of what I have in my mind.NO breaking axis.

enter image description here

UPDATE 2

Well the log-ed transformed values gave the following result. enter image description here

bins = [math.log10(x) for x in range(0, 1000, 50)]
plt.hist(prideG, bins)
plt.xticks(bins)
plt.grid()
plt.show()

On the x axis are the log-ed values of 0-1000 with a step of 50.

  • 3
    Do you mean a [broken axis?](https://matplotlib.org/examples/pylab_examples/broken_axis.html) – Mr. T Feb 22 '18 at 15:42
  • Hmmm, I consider it as last alternative :D. I know that what i want can be done in R for sure but don't know how i matplotlib. What i want is e.g. to have a range from 0 to 50 in ticks of 10 and then another tick of the value 500 and the distance of the tick from 50 to 500 to be equal with that of 0 to 50. – Vangelis Theodorakis Feb 22 '18 at 15:49
  • That would mean rescaling the data and relabeling the y labels with the inverse applied. – mikuszefski Feb 22 '18 at 15:51
  • I don't get the concept. Suddenly at 50 the scaling changes? This would make a bar representing 95 appear equally far away from 50 as a bar representing 45. I think this representation is very misleading. Is this for your own use only? – Mr. T Feb 22 '18 at 16:00
  • P.S.: I don't think the question is a duplicate, since this is not the OP's preferred solution. – Mr. T Feb 22 '18 at 16:11
  • @MrT Whether or not this representation makes sense or is intuitive is not for me to decide here. It is just what I understand from the OP's question. – mikuszefski Feb 22 '18 at 16:17
  • See the problem is that i get values too low on the x axis except those at the first tick. So i want to make them big enough to be readable (that's why the 0-50 scale) and then have the final value of the 1st bar. The reason that broken plot is not my favorite choice is that it does not seem clean to me, but this is a personal opinion. – Vangelis Theodorakis Feb 22 '18 at 16:17
  • @VangelisTheodorakis Most respectable publications will disagree with your personal opinion. You can't hide the break in the axis without raising suspicion of trying to mislead the viewer. To accentuate small in the presence of larger values, logarithmic scaling can be used. – Mr. T Feb 22 '18 at 16:22
  • @MrT OK, no problem....should be reopened though, as you said above. – mikuszefski Feb 22 '18 at 16:23
  • @MrT Yeah, the logarithmic scaling also crossed my mind. – Vangelis Theodorakis Feb 22 '18 at 16:30
  • Solutions to your update exist, cannot post it though as this is falsely closed as duplicate by @ImportanceOfBeingErnest Cheers. Maybe you update your post again and explicitly state " I do not want discontinuous axis as in link ..." – mikuszefski Feb 23 '18 at 07:58
  • use a log scale on the y axis https://matplotlib.org/examples/pylab_examples/log_demo.html – Dan Feb 23 '18 at 10:13
  • There are a lot of possible options and there are answers for each of them already. What would be needed here is that the question makes it clear as to why those (broken axis, rescaling of data, setting xticks manually, use of log scale etc) do not help solve the problem. – ImportanceOfBeingErnest Feb 23 '18 at 10:22
  • ...link two now shows something the OP tries to achieve, while the solution of the accepted answer is not well elaborated (while "duplicate" 1 and 3 remain a non-duplicate). Concerning the comment of @ImportanceOfBeingErnest I disagree; it would not be needed. I'd solve that with a log-y as well, but that's not the point, is it? – mikuszefski Feb 23 '18 at 15:11
  • All duplicates show possible solutions to the question. One might prefer one of them over the other, but that is not part of the question. Note that [ask] specifically says to include a clear problem description, "Search, and research". Now, with the last edit, there is at least an attempt to solve the problem. However, this does not use any of the linked solutions (of course one needs to log the y scale, not the bins); not sure if confusung x with y would actually make this more worthy of reopening. Note that you may always vote to reopen a question; then 5 others need to decide on that. – ImportanceOfBeingErnest Feb 23 '18 at 15:31
  • @ImportanceOfBeingErnest I appreciate your time and effort and agree with most of what you write. All are valid solutions for properly displaying the OP's data. and log bins are truly non-sense. However, I think the OP has a valid question and none of the linked 'duplicates' (after carefully looking at link 2 again, not even that one) answers the question on how to change the scale somewhere on an axes. – mikuszefski Feb 23 '18 at 15:49
  • The question is in thus far not valid as it ignores existing solutions. @mikuszefski If you feel that there is a need for a question and answer here that solves the problem of creating a histogram with a nonlinear y scale, you may ask such question yourself (and possibly answer it). But make sure to stick to [ask] and make clear why a simple log scale (as seen [here](https://stackoverflow.com/questions/17952279/logarithmic-y-axis-bins-in-python)) does not already provide that solution. – ImportanceOfBeingErnest Feb 23 '18 at 16:01
  • Note that there is of course also the option to create a custom scale, as seen [here](https://stackoverflow.com/questions/45306099/how-to-put-different-in-magnitude-values-at-same-distance-on-x-axis). – ImportanceOfBeingErnest Feb 23 '18 at 16:03
  • For the record and to everyone who is complaining about a graph with changing scale: Have a look at matplotlib's default 'symlog' that changes from linear to log. @ImportanceOfBeingErnest The last link is the first one that comes close to a duplicate. Concerning: *...thus far not valid as it ignores existing solutions.* is, considering the context, the most quirky logic I've read on SE so far. Cheers. – mikuszefski Feb 26 '18 at 07:42

0 Answers0