How can I draw the y-axis on both sides of a sns.relplot? - yaxis

relplot/lineplot
I like to have the y-axis also on the right hand side, to be able to see which values are reached at the end of the time series. I do not want a new y-axis, just the same one on both sides of a relplot. Is there any easy solution?
g=sns.relplot(x='year',
y=var,
data=df,
hue='exp',
hue_order=['rcp26','rcp45','rcp85'],
palette=colrcp,
kind='line',
row='region',
row_order=['Scandinavia','Alps', 'Iberian P.', 'Eastern E.'],
height=2, aspect=6,
facet_kws={'sharey': False, 'sharex': True})

Related

Does changing the y-axis and x-axis label changes anything in the image using imshow?

I want to show values as pixels. But my x-axis and y-axis show different range.I don't know what these values are telling us. But I read somewhere that we have to read the values as intensity values. They will not be visualized on the axis. Then what these axis are telling us? Secondly if I use xticks and yticks to label x and y axis does it has any effect on the image? Does it flip anything in the image?
`# a is an array of shape(500,2)
plt.xticks(np.arange(0,2))
plt.yticks(np.arange(0,500))
plt.imshow(a,aspect='auto',cmap=plt.cm.gray)`

Matplotlib: How to place x-axis and y-axis TITLES at edges of frame, even if origin is not at bottom left?

I'm making plots where the (0,0) position is not necessarily in the bottom left corner of the plot frame, meaning that the x and y axes and their ticks cross within the plot frame. It's fine to have the lines, ticks and their values within the frame, but having the axis titles so near to their lines interferes with visualization of certain data points.
I'd simply like to force the x and y axis titles to be at the bottom and far left of the plot frame, respectively; it doesn't work to simply 'pad' the xlabel or ylabel titles because the padding I'd need would vary between plots.
How to get the titles always in these consistent locations of the plot frame, even if the corresponding axis lines, ticks/values may vary in the plot frame space?
Thank you.
I'd like to add a note here. It seemed to me that it could be possible to define the xlabel and ylabel 'labelpad' values directly from the data range:
For example, one could find the minimum x-value of the minimum y-value (this would set the position of the x-axis label), and the minimum x-value of the minimum x-value (this would set the position of the y-axis label):
xpad = ax.get_ylim()[0]
ypad = ax.get_xlim()[0]
Then use these values in xlabel and ylabel parameters as labelpads:
pylab.xlabel("X Title", fontsize=12, labelpad=abs(xpad))
pylab.ylabel("Y Title", fontsize=12, labelpad=abs(ypad))
Unfortunately, it doesn't look like labelpad can accept variables. Any suggestions that might allow a work-around?

How to control the specific size of plot in matplotlib?

Let us suppose that I am plotting a few plots with pyplot/matplotlib. Now, the first has to have tick marks and tick labels, and only the first. The last has to have a colorbar and some marks for scale. If I do a script specifying the figure size, the plot proper in the last and first plots is drawn with smaller sizes, as the figure has to make room for the extra markings. And I seem to be not able to control that, in an automatic way, like making the other plots at the same scale inside a larger figure or something like that.
Example code (it looks a little non-pythonic because I am using PyPlot inside Julia):
using PyPlot
SomeData=randn(64,64,3)
for t=1:3
figure(figsize=(3.0,3.0))
imagen=imshow(SomeData[:,:,t], origin="lower")
if t!=3
xticks([])
yticks([])
else
tick_params(labelsize=8, direction="out")
end
if t==1
cbx=colorbar(imagen, fraction=0.045, ticks=[])
cbx[:set_label]("Some proper English Label", fontsize=8)
end
savefig("CSD-$t.svg",dpi=92)
end
Thanks in advance-

How do create a scale for a second axis without unnecessary (or redundant) plotting?

I have a plot in which I have already plotted all my data and a "twined" axis, on which I'd like to use another scale, in this case dates. I also have a list of all the dates corresponding to each element of my data, and want to add an a scale for the dates to the twined axis.
For example, I have
ax2 = ax1.twinx()
and lists x_temporal_data, y_day_offsets, y_dates, all of the same length, and have already plotted the relationship between the first two with
ax1.plot(x_temporal_data, y_day_offsets)
and I just want to have a scale on ax2 for the dates in y_dates, since y_day_offsets and y_dates are "synonyms" for the same time information.
Is there a way to do this without "plotting" something I don't need to display (since all my data is already plotted). For example, I can get the dates to appear perfectly on ax2 with
ax2.plot(len(y_dates)*[some_random_out_of_xrange_value], y_dates)
but that seems like a hack: plotting nothing to "calibrate" the second axis.
Is there a better, more idiomatic way of accomplishing this?
Simply set the scale on the second y-axis to your liking with:
ax2.set_ylim([min(y_dates), max(y_dates)])

Matplotlib tick labels

Is there a way to render the tick labels just right inside the axes, i.e, something like the direction property there is on the ticks themself?
Right now I'm setting the x property to a positive value on the ticklabels to draw them inside of the axis, i.e.,
ax2.set_yticklabels(['0', '2500', '5000', '7500'], minor=False, x=0.05)
But this doesn't really work on resizable plots, as the 0.05 figure is absolute (and too big on big plots).
Any ideas?
I'm assuming that ax2 is constructed as ax2 = ax.twinx(), which is to say that it is on the right side of the axes.
You could do something like the following:
ax2.set_yticklabels(['0', '2500', '5000', '7500'], minor=False, horizontalalignment='right')
for tick in ax2.yaxis.get_major_ticks():
tick.set_pad(-8)
If you want the left side axis on the inside too, then you'd simply switch the horizontal alignment to 'left' and change the pad from -8 to -25.
The two numbers might not be exact and could depend on other matplotlib settings you might have (e.g. length of major ticks) so you may want to increase or decrease those values slightly.