Skip to content
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

Drawing a colorbar with pg.mplviewer.drawModel #130

Closed
Coastal0 opened this issue Jan 30, 2018 · 6 comments
Closed

Drawing a colorbar with pg.mplviewer.drawModel #130

Coastal0 opened this issue Jan 30, 2018 · 6 comments

Comments

@Coastal0
Copy link

Hi guys,

I'm trying to draw a colorbar with the drawModel command. To my mind, the interpolation tutorial suggests it's possible (by means of showCbar = False) however setting this to 'True' does nothing.

I introduced a colorbar through the matplotlib which seems to work just fine.

dataplot = pg.mplviewer.drawModel(ax = ax, mesh = meshInv, data = datInv, colorBar=True, cmap='jet_r', showMesh=0, cMin = 10, cMax = 2000)
cb = plt.colorbar(dataplot)

Should drawModel be taking the showCbar command?

@florian-wagner
Copy link
Member

No, drawModel only draws the model into a specified axes. Please use pg.viewer.showMesh or pg.show for high-level plotting, which will take the argument colorBar=True.

import pygimli as pg

mesh = pg.createGrid([0,1,2], [0,1,2])
data = pg.randn(mesh.cellCount())

pg.show(mesh, data, colorBar=True)
pg.show(mesh, data, colorBar=True, orientation="vertical")

image

@Coastal0
Copy link
Author

On a related (but not new topic-worthy) note;

How on earth are you supposed to access these ticklabels?
I simply want them in a different format (i.e. not 10^2,3 etc), yet I can't access them in the same way I would if it were simply matplotlib.

This code below, for example, (and based on my earlier question), does exactly what I'd like it to do;

dataplot = pg.mplviewer.drawModel(...parameters...)
cb = plt.colorbar(dataplot, orientation = 'horizontal', format = '%.i',aspect = 50)

figure_1

But when creating the colorbar through pg.show, I can't see how to access the same format options.

ax, cb = pg.show(meshERT, resBulk, colorBar=True, cmap='jet_r', showMesh=0)

figure_1-2

I can turn them to integers with the following;

cb.ax.xaxis.set_ticklabels(cb.get_ticks().astype(int), minor = False)

However this shows them all, when I just want to change the existing set of shown numbers.
figure_1-3

Reading through Florian's links to colorbars, I can't see a way of changing the format. I'm at the point now where it's better to ask than keep getting nowhere alone...!

@halbmy
Copy link
Contributor

halbmy commented Jan 31, 2018

The new 10^x colorbars (from mpl 2.1 or 2.2 on) are indeed a bit nasty.

It is true, pg.mplviewer.createColorbar (https://www.pygimli.org/pygimliapi/_generated/pygimli.mplviewer.html?highlight=colorbar#pygimli.mplviewer.createColorBar) does not (unlike createColorBarOnly) pass additional keyword arguments to mpl.colorbar (maybe it should), but it returns the colorbar object that can be manipulated afterwards.

@Coastal0
Copy link
Author

What actor (If that's the right term?) does pg.show put out?

For example, in the earlier code, the plt.colorbar command takes the pg.drawModel output, however I can't seem to find the similar object from pg.show

I guess it's a patch-style object, but I'm just not sure how to get at it.

@halbmy
Copy link
Contributor

halbmy commented Jan 31, 2018

pg.show alias pg.viewer.show redirects to pg.viewer.showMesh and returns the axis and the colorbar object: ax, cbar = pg.show(mesh, property, colorBar=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants