Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cf4bccf
image compare
lassejsc Oct 3, 2025
f0c0ce5
newline at end of file
lassejsc Oct 3, 2025
5cfdc5e
Horizontal colorbar added to plot_colormap
lassejsc Oct 3, 2025
bc1bb6b
added horizontal colorbars to colormap,vdf and vdfdiff
lassejsc Oct 8, 2025
b7e8ea5
Removed junk file
lassejsc Oct 8, 2025
bc31a3d
old versions of files from other branch were accidentally added to th…
lassejsc Oct 8, 2025
1010bfc
added horizontal colorbar to plot_ionosphere and plot_isosurface
lassejsc Oct 9, 2025
c498980
added horizontal colorbar to colormapt3dslice too
lassejsc Oct 9, 2025
9b7b8e6
Merge branch 'master' into horizontal_colorbar
lassejsc Oct 10, 2025
569ab79
Merge branch 'master' into horizontal_colorbar
lassejsc Oct 10, 2025
1e54e7c
Horizontal colorbar defaults
lassejsc Oct 10, 2025
9145828
adjusted label so highres scaling is sensible and added horizontal co…
lassejsc Oct 10, 2025
dd55b12
added horizontal colorbar call to testpackage vdf
lassejsc Oct 10, 2025
025edfe
Revert "added horizontal colorbar to colormapt3dslice too"
lassejsc Oct 13, 2025
0a36719
Horizontal colorbar support
lkotipal May 22, 2024
fd20c59
Fixed horzontal colorbar text alignment and the plot alignment within…
lassejsc Oct 13, 2025
d632e99
Added default colorbar that goes under the mainplot for plot_vdfdiff,…
lassejsc Oct 15, 2025
26520fa
matplotlib is annoying so i just reduced the number of ticks for hori…
lassejsc Oct 15, 2025
8e3e6f2
plot_ionosphere default position for horizontal colorbar
lassejsc Oct 15, 2025
ea5f8f1
reverted back the colorbar title because it suddenly works?
lassejsc Oct 15, 2025
155dff3
plot_colormap3dslice horizontal colorbar
lassejsc Oct 15, 2025
3e10900
plot_neutral_sheet default horizontal cb position
lassejsc Oct 16, 2025
d497c4b
plot_vdf colorbal position adjustements
lassejsc Oct 16, 2025
02bf10c
vdfdiff colorbar position minor adjustements
lassejsc Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions analysator/pyPlots/plot_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def plot_colormap(filename=None,
highres=None,
vectors=None, vectordensity=100, vectorcolormap='gray', vectorsize=1.0,
streamlines=None, streamlinedensity=1, streamlinecolor='white',streamlinethick=1.0,
axes=None, cbaxes=None, useimshow=False, imshowinterp='none', flipxaxis=False,
axes=None, cbaxes=None,cb_horizontal=False, useimshow=False, imshowinterp='none', flipxaxis=False,
):

''' Plots a coloured plot with axes and a colour bar.
Expand Down Expand Up @@ -196,6 +196,7 @@ def plot_colormap(filename=None,
Note that the aspect ratio of the colormap is made equal in any case, hence the axes
proportions may change if the box and axes size are not designed to match by the user
:kword cbaxes: Provide the routine a set of axes for the colourbar.
:kword cb_horizontal: Set to draw the colorbar horizontally instead of vertically (default: False) requires cbaxes to be set.
:kword useimshow: Use imshow for raster background instead (default: False)
:kword imshowinterp: Use this matplotlib interpolation for imshow (default: 'none')
:kword flipxaxis: Invert output plot x/horizontal axis so that e.g. the Sun is on the left (default: False)
Expand Down Expand Up @@ -866,7 +867,7 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Logarithmic plot
norm = LogNorm(vmin=vminuse,vmax=vmaxuse)
ticks = LogLocator(base=10,subs=list(range(10))) # where to show labels
ticks = LogLocator(base=10,subs=(1.0,) if cb_horizontal else list(range(10))) # where to show labels
else:
# Linear
linticks = 7
Expand Down Expand Up @@ -1154,9 +1155,14 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Split existing axes to make room for colorbar
divider = make_axes_locatable(ax1)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbdir="right"; horalign="left"

if cb_horizontal:
cax = divider.append_axes("bottom", size="4%", pad=0.55*scale)
ax1.xaxis.set_label_coords(0.5,-0.18)
horalign="center"
else:
cax = divider.append_axes("right", size="5%", pad=0.05)
horalign="left"
cbdir="right"
# Set flag which affects colorbar decimal precision
if lin is None:
pt.plot.cb_linear = False
Expand All @@ -1165,18 +1171,18 @@ def exprMA_cust(exprmaps, requestvariables=False):

# First draw colorbar
if usesci:
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False,orientation='horizontal' if cb_horizontal else 'vertical')
else:
#cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FormatStrFormatter('%4.2f'), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False,orientation='horizontal' if cb_horizontal else 'vertical')
cb.outline.set_linewidth(thick)
cb.ax.yaxis.set_ticks_position(cbdir)
# Ensure minor tick marks are off
if lin is not None:
cb.minorticks_off()

if not cbaxes:
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick)
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick,rotation=30 if cb_horizontal else 0)
cb_title = cax.set_title(cb_title_use,fontsize=fontsize3,fontweight='bold', horizontalalignment=horalign)
cb_title.set_position((0.,1.+0.025*scale)) # avoids having colourbar title too low when fontsize is increased
else:
Expand All @@ -1188,6 +1194,7 @@ def exprMA_cust(exprmaps, requestvariables=False):
fig.canvas.draw() # draw to get tick positions

# Adjust placement of innermost ticks for symlog if it indeed is (quasi)symmetric
# Might need additions for horizontal cb?
if symlog is not None and np.isclose(vminuse/vmaxuse, -1.0, rtol=0.2):
cbt=cb.ax.yaxis.get_ticklabels()
(cbtx,cbty) = cbt[len(cbt)//2-1].get_position() # just below zero
Expand Down
22 changes: 15 additions & 7 deletions analysator/pyPlots/plot_colormap3dslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def plot_colormap3dslice(filename=None,
highres=None,
vectors=None, vectordensity=100, vectorcolormap='gray', vectorsize=1.0,
streamlines=None, streamlinedensity=1, streamlinecolor='white', streamlinethick=1.0,
axes=None, cbaxes=None,
axes=None, cbaxes=None,cb_horizontal=False,
normal='y', cutpoint=0., cutpointre=None, flipxaxis=False,
useimshow=False, imshowinterp='none',
):
Expand Down Expand Up @@ -211,6 +211,7 @@ def plot_colormap3dslice(filename=None,
Note that the aspect ratio of the colormap is made equal in any case, hence the axes
proportions may change if the box and axes size are not designed to match by the user
:kword cbaxes: Provide the routine a set of axes for the colourbar.
:kword cb_horizontal: Set to draw the colorbar horizontally instead of vertically (default: False) requires cbaxes to be set.
:kword normal: Direction of the normal of the 2D cut through ('x', 'y', or 'z' or a vector along x,y, or z)
:kword cutpoint: Coordinate (in normal direction) through which the cut must pass [m]
:kword cutpointre: Coordinate (in normal direction) through which the cut must pass [rE]
Expand Down Expand Up @@ -1107,7 +1108,7 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Logarithmic plot
norm = LogNorm(vmin=vminuse,vmax=vmaxuse)
ticks = LogLocator(base=10,subs=range(10)) # where to show labels
ticks = LogLocator(base=10,subs=(1.0,) if cb_horizontal else list(range(10))) # where to show labels
else:
# Linear
levels = MaxNLocator(nbins=255).tick_values(vminuse,vmaxuse)
Expand Down Expand Up @@ -1474,8 +1475,14 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Split existing axes to make room for colorbar
divider = make_axes_locatable(ax1)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbdir="right"; horalign="left"
if cb_horizontal:
cax = divider.append_axes("bottom", size="4%", pad=0.55*scale)
ax1.xaxis.set_label_coords(0.5,-0.18)
horalign="center"
else:
cax = divider.append_axes("right", size="5%", pad=0.05)
oralign="left"
cbdir="right"

# Colourbar title
if len(cb_title_use)!=0:
Expand All @@ -1489,18 +1496,19 @@ def exprMA_cust(exprmaps, requestvariables=False):

# First draw colorbar
if usesci:
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False,orientation='horizontal' if cb_horizontal else 'vertical')
else:
#cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FormatStrFormatter('%4.2f'), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False,orientation='horizontal' if cb_horizontal else 'vertical')
cb.outline.set_linewidth(thick)
cb.ax.yaxis.set_ticks_position(cbdir)
# Ensure minor tick marks are off
if lin is not None:
cb.minorticks_off()

if not cbaxes:
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick)

cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick,rotation=30 if cb_horizontal else 0)
cb_title = cax.set_title(cb_title_use,fontsize=fontsize3,fontweight='bold', horizontalalignment=horalign)
cb_title.set_position((0.,1.+0.025*scale)) # avoids having colourbar title too low when fontsize is increased
else:
Expand Down
23 changes: 15 additions & 8 deletions analysator/pyPlots/plot_ionosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def plot_ionosphere(filename=None,
usesci=True, log=None,
lin=None, symlog=None, nocb=False, internalcb=False,
minlatitude=60,
cbtitle=None, title=None, cbaxes=None,
cbtitle=None, title=None, cbaxes=None,cb_horizontal=False,
thick=1.0,scale=1.0,vscale=1.0,
wmark=False,wmarkb=False,
viewdir=1.0,draw=None,
Expand Down Expand Up @@ -84,6 +84,7 @@ def plot_ionosphere(filename=None,
variables.
:kword axes: Provide the routine a set of axes to draw within instead of generating a new image.
:kword cbaxes: Provide the routine a set of axes for the colourbar.
:kword cb_horizontal: Set to draw the colorbar horizontally instead of vertically (default: False) requires cbaxes to be set.
:kword thick: line and axis thickness, default=1.0
:kword draw: Set to anything but None or False in order to draw image on-screen instead of saving to file (requires x-windowing)
:kword wmark: If set to non-zero, will plot a Vlasiator watermark in the top left corner. If set to a text
Expand Down Expand Up @@ -390,7 +391,7 @@ def plot_ionosphere(filename=None,
else:
# Logarithmic plot
norm = LogNorm(vmin=vminuse,vmax=vmaxuse)
ticks = LogLocator(base=10,subs=list(range(10))) # where to show labels
ticks = LogLocator(base=10,subs=(1.0,) if cb_horizontal else list(range(10))) # where to show labels
else:
# Linear
linticks = 7
Expand All @@ -416,9 +417,10 @@ def plot_ionosphere(filename=None,
ax_polar.set_frame_on(False)
ax_polar.set_aspect('equal')
else:
axes.axis('off')
axes.set_xticklabels([])
axes.set_yticklabels([])
ax_cartesian = inset_axes(parent_axes=axes, width="80%", height="80%", borderpad=1, loc='center left')
ax_cartesian = inset_axes(parent_axes=axes, width="80%", height="80%", borderpad=1, loc='center' if cb_horizontal else 'center left')
ax_cartesian.set_xlim(-(90-minlatitude),(90-minlatitude))
ax_cartesian.set_ylim(-(90-minlatitude),(90-minlatitude))
ax_cartesian.set_aspect('equal')
Expand Down Expand Up @@ -486,7 +488,8 @@ def make_circle(r):
if cbaxes:
# Colorbar axes are provided
cax = cbaxes
cbdir="right"; horalign="left"
cbdir="right"
horalign="center" if cb_horizontal else "left"
elif internalcb:
# Colorbar within plot area
cbloc=1; cbdir="left"; horalign="right"
Expand All @@ -505,7 +508,11 @@ def make_circle(r):
else:
# Split existing axes to make room for colorbar
if axes is None:
cax = fig.add_axes([0.9,0.2,0.03,0.6])
if cb_horizontal:
cax = fig.add_axes([0.1,-0.1,0.6,0.03])
else:
cax = fig.add_axes([0.9,0.2,0.03,0.6])

else:
cax = axes.inset_axes([0.9,0.2,0.03,0.6])
cbdir="right"; horalign="left"
Expand All @@ -518,15 +525,15 @@ def make_circle(r):

# First draw colorbar
if usesci:
cb = plt.colorbar(contours, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False)
cb = plt.colorbar(contours, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False,orientation="horizontal" if cb_horizontal else "vertical")
else:
#cb = plt.colorbar(contours, ticks=ticks, format=mtick.FormatStrFormatter('%4.2f'), cax=cax, drawedges=False)
cb = plt.colorbar(contours, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False)
cb = plt.colorbar(contours, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False,orientation="horizontal" if cb_horizontal else "vertical")
cb.outline.set_linewidth(thick)
cb.ax.yaxis.set_ticks_position(cbdir)

if not cbaxes:
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick)
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick,rotation=30 if cb_horizontal else 0)
cb_title = cax.set_title(cb_title_use,fontsize=fontsize3,fontweight='bold', horizontalalignment=horalign)
cb_title.set_position((0.,1.+0.025*scale)) # avoids having colourbar title too low when fontsize is increased
else:
Expand Down
22 changes: 15 additions & 7 deletions analysator/pyPlots/plot_isosurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def plot_neutral_sheet(filename=None,
highres=None,
vectors=None, vectordensity=100, vectorcolormap='gray', vectorsize=1.0,
streamlines=None, streamlinedensity=1, streamlinecolor='white', streamlinethick=1.0,
axes=None, cbaxes=None,
axes=None, cbaxes=None,cb_horizontal=False,
useimshow=False, imshowinterp='none', folding_alpha=0.2, z_extent=[-5,5], sheetlayer='above'
):

Expand Down Expand Up @@ -940,6 +940,7 @@ def plot_neutral_sheet(filename=None,
Note that the aspect ratio of the colormap is made equal in any case, hence the axes
proportions may change if the box and axes size are not designed to match by the user
:kword cbaxes: Provide the routine a set of axes for the colourbar.
:kword cb_horizontal: Set to draw the colorbar horizontally instead of vertically (default: False) requires cbaxes to be set.
:kword normal: Direction of the normal of the 2D cut through ('x', 'y', or 'z' or a vector)
:kword cutpoint: Coordinate (in normal direction) through which the cut must pass [m]
:kword cutpointre: Coordinate (in normal direction) through which the cut must pass [rE]
Expand Down Expand Up @@ -1627,7 +1628,7 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Logarithmic plot
norm = LogNorm(vmin=vminuse,vmax=vmaxuse)
ticks = LogLocator(base=10,subs=range(10)) # where to show labels
ticks = LogLocator(base=10,subs=(1.0,) if cb_horizontal else list(range(10))) # where to show labels
else:
# Linear
levels = MaxNLocator(nbins=255).tick_values(vminuse,vmaxuse)
Expand Down Expand Up @@ -1820,8 +1821,15 @@ def exprMA_cust(exprmaps, requestvariables=False):
else:
# Split existing axes to make room for colorbar
divider = make_axes_locatable(ax1)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbdir="right"; horalign="left"
if cb_horizontal:
cax = divider.append_axes("bottom", size="4%", pad=0.55*scale)
ax1.xaxis.set_label_coords(0.5,-0.18)
horalign="center"
else:
cax = divider.append_axes("right", size="5%", pad=0.05)
horalign="left"
cbdir="right"


# Colourbar title
if len(cb_title_use)!=0:
Expand All @@ -1835,18 +1843,18 @@ def exprMA_cust(exprmaps, requestvariables=False):

# First draw colorbar
if usesci:
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmtsci), cax=cax, drawedges=False,orientation="horizontal" if cb_horizontal else "vertical")
else:
#cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FormatStrFormatter('%4.2f'), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False)
cb = plt.colorbar(fig1, ticks=ticks, format=mtick.FuncFormatter(pt.plot.cbfmt), cax=cax, drawedges=False,orientation="horizontal" if cb_horizontal else "vertical")
cb.outline.set_linewidth(thick)
cb.ax.yaxis.set_ticks_position(cbdir)
# Ensure minor tick marks are off
if lin is not None:
cb.minorticks_off()

if not cbaxes:
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick)
cb.ax.tick_params(labelsize=fontsize3,width=thick,length=3*thick,rotation=30 if cb_horizontal else 0)
cb_title = cax.set_title(cb_title_use,fontsize=fontsize3,fontweight='bold', horizontalalignment=horalign)
cb_title.set_position((0.,1.+0.025*scale)) # avoids having colourbar title too low when fontsize is increased
else:
Expand Down
Loading