-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aspect on semi-log plots #996
Comments
I've noticed this as well and haven't yet been able to figure out what's going on here. Presumeably this expression doesn't work correctly with log axes:
|
When running for the first time, this warning appears:
|
Thanks, wonder what the correct way of setting log-linear plot aspects is then. |
A solution inspired from stackoverflow answer: def fixed_aspect_ratio_loglog(plot, element):
'''
Set a fixed aspect ratio on matplotlib loglog plots
regardless of axis units
'''
ratio = plot._aspect_param_value
ax = plot.handles['axis']
xvals,yvals = ax.axes.get_xlim(),ax.axes.get_ylim()
xrange = np.log(xvals[1])-np.log(xvals[0])
yrange = np.log(yvals[1])-np.log(yvals[0])
ax.set_aspect(ratio*(xrange/yrange), adjustable='box')
|
Assigned myself, will look into it. |
Hi, @philippjfr . I'm sorry for bothering. Any progress on this? I did this import numpy as np
def fixed_aspect_ratio_loglog(plot, element):
'''
Set a fixed aspect ratio on matplotlib loglog plots
regardless of axis units
'''
ratio = plot.aspect
ax = plot.handles['axis']
xvals,yvals = ax.axes.get_xlim(),ax.axes.get_ylim()
print xvals,yvals
xrange=xvals[1]-xvals[0]
#if ax.get_xaxis().get_scale()=='log':#or linear
if plot.logx:
xrange = np.log(xvals[1])-np.log(xvals[0])
yrange=yvals[1]-yvals[0]
#if plot._logy_param_value:
#if ax.get_yaxis().get_scale()=='log':
if plot.logy:
yrange = np.log(yvals[1])-np.log(yvals[0])
print ax.get_aspect()
print xrange,yrange,ratio
ax.set_aspect(ratio*(xrange/yrange), adjustable='box')
print ax.get_aspect()
plot=curve(plot=dict(logx=True,aspect=1,final_hooks=[fixed_aspect_ratio_loglog]),style=dict(width=800,height=600))
plot And got this
And these warnings:
Thank you for your help! |
Keeping this open, we have a fix for loglog plots now, but not semilog. |
A temporary solution is to set the figure size to force it to be square:
the 1.1 scaling is for avoiding cuts in the labels, should be adapted for case to case. |
I have a log scale on my y-axis and wish to stretch out the x-axis, is there a workaround for achieving this? |
Just hit this issue. Would be great to see a fix. |
@philippjfr - You say you have a fix for
Results in something like this: Am I doing something inherently wrong with trying to get an equal aspect ratio? Is there any workaround? I've also tried setting the Similar code, but for non log/log gives something like this: |
The aspect parameter can be used to set the aspect of a plot:
However, when setting one of the axis to log, the aspect parameter is ignored:
The text was updated successfully, but these errors were encountered: