colorbar with Axes3D for a set of collections?

Hi,

I am trying to plot a set of simulation results of FEM simulations.
With a lot of help from Ben I can plot the deformed shape quite nicely
but I have trouble in applying a colorbar to the plot.

In the attached file there are three results with different results.

How can I apply a "global" colorbar so that all collections are nicely
represented?

Thanks a lot in advance,
Daniel

3D_colorbar.py (2 KB)

Hi,

I am trying to plot a set of simulation results of FEM simulations.
With a lot of help from Ben I can plot the deformed shape quite nicely
but I have trouble in applying a colorbar to the plot.

In the attached file there are three results with different results.

How can I apply a "global" colorbar so that all collections are nicely
represented?

Quick thoughts with no testing or concrete examples:

1) Don't set the cmap or norm for the colorbar; let it inherit those properties from the mappable to which it is connected.

2) Ensure that the cmap and norm are the same for all collections. You are already taking care of the cmap, so the problem is that you are autoscaling the collections separately, which is setting vmin and vmax to different values for the different collections. Use the data to figure out the range (vmin, vmax) that you want the colors to span, and then for each collection, instead of col.autoscale(), use

  col.norm.vmin = vmin
  col.norm.vmax = vmax

(You could also make a single norm instance for all the collections to use, just as with the cmap, so that you only have to set vmin and vmax once.)

Eric

···

On 01/13/2011 01:40 PM, Daniel Mader wrote:

Thanks a lot in advance,
Daniel

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Eric,

thanks for your feedback, it helped a lot! I have some questions left,
see below.

2011/1/14 Eric Firing <efiring@...202...>:

Quick thoughts with no testing or concrete examples:

1) Don't set the cmap or norm for the colorbar; let it inherit those
properties from the mappable to which it is connected.

Am I doing this correctly in the attached code? It seems there are
several ways of doing this... Which is the suggested one? How can I
label the colorbar?

2) Ensure that the cmap and norm are the same for all collections. You
are already taking care of the cmap, so the problem is that you are
autoscaling the collections separately, which is setting vmin and vmax
to different values for the different collections. Use the data to
figure out the range (vmin, vmax) that you want the colors to span, and
then for each collection, instead of col.autoscale(), use

   col\.norm\.vmin = vmin
   col\.norm\.vmax = vmax

That was what I needed, see code :slight_smile:

(You could also make a single norm instance for all the collections to
use, just as with the cmap, so that you only have to set vmin and vmax
once.)

And this I don't understandm could you please elaborate?

Thanks a very lot in advance
best regards from Austria,

Daniel

3D_colorbar.py (2.24 KB)

Hi Eric,

thanks for your feedback, it helped a lot! I have some questions left,
see below.

2011/1/14 Eric Firing<efiring@...202...>:

Quick thoughts with no testing or concrete examples:

1) Don't set the cmap or norm for the colorbar; let it inherit those
properties from the mappable to which it is connected.

Am I doing this correctly in the attached code? It seems there are
several ways of doing this... Which is the suggested one? How can I
label the colorbar?

The way you did it is fine. For the label, modify by keeping a reference to the colorbar and then calling set_label:

cb = fig.colorbar(collist[-1], shrink=0.85,)#, aspect=5)
cb.set_label('whatever this is')

2) Ensure that the cmap and norm are the same for all collections. You
are already taking care of the cmap, so the problem is that you are
autoscaling the collections separately, which is setting vmin and vmax
to different values for the different collections. Use the data to
figure out the range (vmin, vmax) that you want the colors to span, and
then for each collection, instead of col.autoscale(), use

        col.norm.vmin = vmin
        col.norm.vmax = vmax

That was what I needed, see code :slight_smile:

(You could also make a single norm instance for all the collections to
use, just as with the cmap, so that you only have to set vmin and vmax
once.)

And this I don't understandm could you please elaborate?

See attached modification.

Eric

3D_colorbar.py (1.98 KB)

···

On 01/14/2011 02:02 AM, Daniel Mader wrote:

Thanks a very lot in advance
best regards from Austria,

Daniel

Thank you very much for your patience, your explanations helped me a
very lot in getting beautiful plots for my thesis!
Best regards,
Daniel