Is there a way to change the orientation of the colorbar in Plotly heatmap? Setting the orientation in the layout does not do anything:
go.Layout(
legend=dict(
orientation="h")
)
It doesn't even give me an error message. I have also tried change the orientation in the colorbar directly:
colorbar = dict(
orientation="h"
)
but I get the error message that 'orientation' is not a valid property of 'plotly.graph_objs.heatmap.ColorBar'.
I know how to set the position of the colorbar and I have looked the valid properties of the colorbar but could not find a way to set its orientation. Is this possible?
Set the orientation of the colorbar.
As per the Plotly Documentation:
# For the vertical orintation
fig.update_traces(colorbar_orientation='v', selector=dict(type='heatmap'))
# For the horizontal orintation
fig.update_traces(colorbar_orientation='h', selector=dict(type='heatmap'))
Default: "v" #vertical
I don't believe so. According to this open issue and the response from Chriddyp (co-founder of Plotly), a horizontal colorbar has not been implemented but this feature may be added in future releases of Plotly.
If you really need it— I suppose you can try to draw the colorbar yourself using annotations but that's admittedly a lot of work.
Related
I have a figure in matplotlib where two axes overlap one-another. The axes draw according to the order in which they were created in the code, as shown when I print fig.axes, which returns [<matplotlib.axes._subplots.AxesSubplot object at 0x0000021C7417B320>, <matplotlib.axes._subplots.AxesSubplot object at 0x0000021C72371630>]. I would like to change the order so that the second axes created draws first. The property fig.axes is not writeable, so I unfortunately can't create a new list with the order I need and then assign it. I've also tried using ax.set_zorder() where I specified ax1.set_zorder(0) and ax2.set_zorder(1), but this did not work, and neither did the reverse or larger integer values. I can't seem to find anything in the documentation that would allow me to change the order in which axes are drawn, does anyone know of a way?
Purpose
As you can see, the grey year labels along the x-axis are covered by the black date call-outs. The year labels are part of ax1 and the date labels ax2. I'd like to switch the order so that ax1 is drawn above ax2, so as to not cover the year text.
Thanks for any help and suggestions!
Could someone show me how to leave extra space on top of a FacetGrid? I try to put a super title to the top of a FacetGrid plot but end up with the super-title overlapping with the subplot titles due to very limited margin on top in the default setting.
Thanks
Use the Figure method subplots_adjust to add space to the top of the plot:
g = sns.lmplot("x", "y", col="c", data=df)
g.figure.suptitle("Title of the plot", size=16)
g.figure.subplots_adjust(top=.9)
.suptitle(...) is a matplotlib figure function. It has x and y arguments, with y=0.98 as the default. You can adjsut it to be a bit higher, instead of moving the subplots (in some cases you may not have enough freedom there).
g.fig.suptitle("My super title", y=1.05)
In Matplotlib, I make dashed grid lines as follows:
fig = pylab.figure()
ax = fig.add_subplot(1,1,1)
ax.yaxis.grid(color='gray', linestyle='dashed')
however, I can't find out how (or even if it is possible) to make the grid lines be drawn behind other graph elements, such as bars. Changing the order of adding the grid versus adding other elements makes no difference.
Is it possible to make it so that the grid lines appear behind everything else?
According to this - http://matplotlib.1069221.n5.nabble.com/axis-elements-and-zorder-td5346.html - you can use Axis.set_axisbelow(True)
(I am currently installing matplotlib for the first time, so have no idea if that's correct - I just found it by googling "matplotlib z order grid" - "z order" is typically used to describe this kind of thing (z being the axis "out of the page"))
To me, it was unclear how to apply andrew cooke's answer, so this is a complete solution based on that:
ax.set_axisbelow(True)
ax.yaxis.grid(color='gray', linestyle='dashed')
If you want to validate the setting for all figures, you may set
plt.rc('axes', axisbelow=True)
or
plt.rcParams['axes.axisbelow'] = True
It works for Matplotlib>=2.0.
I had the same problem and the following worked:
[line.set_zorder(3) for line in ax.lines]
fig.show() # to update
Increase 3to a higher value if it does not work.
You can also set the zorder kwarg in matplotlib.pyplot.grid
plt.grid(which='major', axis='y', zorder=-1.0)
You can try to use one of Seaborn's styles. For instance:
import seaborn as sns
sns.set_style("whitegrid")
Not only the gridlines will get behind but the looks are nicer.
For some (like me) it might be interesting to draw the grid behind only "some" of the other elements. For granular control of the draw order, you can use matplotlib.artist.Artist.set_zorder on the axes directly:
ax.yaxis.grid(color='gray', linestyle='dashed')
ax.set_zorder(3)
This is mentioned in the notes on matplotlib.axes.Axes.grid.
How can I change the size of only the yaxis label?
Right now, I change the size of all labels using
pylab.rc('font', family='serif', size=40)
but in my case, I would like to make the y-axis label larger than the x-axis. However, I'd like to leave the tick labels alone.
I've tried, for example:
pylab.gca().get_ylabel().set_fontsize(60)
but I only get:
AttributeError: 'str' object has no attribute 'set_fontsize'
So, obviously that doesn't work. I've seen lots of stuff for tick sizes, but nothing for the axis labels themselves.
If you are using the 'pylab' for interactive plotting you can set the labelsize at creation time with pylab.ylabel('Example', fontsize=40).
If you use pyplot programmatically you can either set the fontsize on creation with ax.set_ylabel('Example', fontsize=40) or afterwards with ax.yaxis.label.set_size(40).
I'm using Python to plot a couple of graphs and I'm trying to change the formatting and essentially 'brand' the graph. I've managed to change most things using pylab.rcParams[...], but I can't work out how to change the colour of the markers on the axes and the border around the legend. Any help would be much appreciated. The line below is an example of the type of code I've been using to edit other parts. Basically just lines taken from matplotlibrc, but I can't find them to change everything I want.
pylab.rcParams[axes.labelcolor' = '#031F73'
If you just want to use rcParams, the proper parameters are xticks.color and yticks.color. I can't seem to find a key for the legend frame color. You can set that (along with the tick colors) programmatically though.
import pylab
pylab.plot([1,2,3],[4,5,6], label ='test')
lg = pylab.legend()
lg.get_frame().set_edgecolor('blue')
ax = pylab.axes()
for line in ax.yaxis.get_ticklines():
line.set_color('blue')
for line in ax.xaxis.get_ticklines():
line.set_color('blue')
for label in ax.yaxis.get_ticklabels():
label.set_color('blue')
for label in ax.xaxis.get_ticklabels():
label.set_color('blue')
pylab.show()