1

I have this graph and although the data below 0% is important enough that it needs to be displaying, it's too infrequent to warrant skewing the entire graph. Is there a way to make it such that below 0% the scale is reduced/compressed so the same distance gives a larger change in %. (I don't want to use a broken axis because there may be other data <0%)

I have seen this is possible way of doing it however all I want is a linear scale for < 0%, just with a different scaling value. Is there any easy way of doing this?

8
  • Changing your yaxis to log scale is the only way I can think of!
    – Srivatsan
    Jul 31, 2015 at 9:15
  • @ThePredator can't have a logscale for negative y values...
    – tmdavison
    Jul 31, 2015 at 9:38
  • If anything it makes the problem worse as the section with most of the data in is compressed to the top quarter of the graph (and subtleties in the data are less clear) Edit: and what @tom said
    – sanso
    Jul 31, 2015 at 9:43
  • @tom Yeah!! Forgot!!
    – Srivatsan
    Jul 31, 2015 at 11:56
  • Would it be possible to embed your image this graph in your OP and also to add a minimal example of the code you are currently using to plot your graph. Jul 31, 2015 at 13:48

2 Answers 2

0

I think your only option would be indeed to create a custom projection for your axes. In theory it shouldn't be too difficult since you want a linear scale with just a different scale for positive and negative values, but you'll still have to to write quite a bit of code to create the relevant class.

http://matplotlib.org/devel/add_new_projection.html and as you already linked: http://matplotlib.org/examples/api/custom_scale_example.html

0

So I found a work around but it's a bit of a fudge. This is what it looks like.

Here's the code:

fig, ax = plt.subplots()
fig.canvas.set_window_title("Frame-to-frame pump-to-probe")
plt.xlabel(r'$t/ps$')
plt.ylabel(r'%')
min = 0
for i in range(len(ftf_PtmPlist)):
    if ftf_PtmPlist[i] < min:
        min = ftf_PtmPlist[i]
    if ftf_PtmPlist[i] < 0:
        ftf_PtmPlist[i] = 2*ftf_PtmPlist[i]/10.0
for i in range(len(ftf_PttPlist)):
    if ftf_PttPlist[i] < min:
        min = ftf_PttPlist[i]
    if ftf_PttPlist[i] < 0:
        ftf_PttPlist[i] = 2*ftf_PttPlist[i]/10.0
lables = [0,20,40,60,80,100]
ymin = int(20*math.floor(min/100.0))
for y in range(ymin,-19,20):
    lables.append(y)
lables = sorted(lables)
for i in range(-ymin/20):
    lables[i] = str(int(lables[i]*10/2.0))
ax.set_yticklabels(lables)
plt.plot(timelist,ftf_PtmPlist,'magenta', label='pump to main probe efficiency')
plt.plot(timelist,ftf_PttPlist,'teal', label='pump to total probe efficiency')
plt.plot(timelist,p_deplist,'orange', label='pump energy depletion')
plt.gca().set_ylim(top=105)
plt.gca().set_xlim(left=-1.0)
plt.legend(bbox_to_anchor=(0.55, 0.17), loc=2, borderaxespad=0., prop={'size':10})

First I scale all values less than 0 by a factor of 0.2 for the two list which have the possibility for negative values while simultaneously looking for the most negative value overall. I then use this value to find what the most negative tick label should be (given the scaling I'm using) and create a list of new tick labels so the negative values display as the values they had before I scaled them down.

I know it's a bit sloppy but it does the job!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.