2 axes bar chart -- malformed header from script. Bad headerRe: colorbar with 2 different scales

Hi, P.Romero,
Please let me know if you get this working. I am trying to do the same type of 2 axes bar chart. but I got error message.
I am using regular bar ().
the following is the email i sent a week ago. Eric, I did use the twinx(), but it gave errors.

thanks in advance.

Hi, everyone,
I am a matplotlib beginner. I am trying to do a chart with 2 y axes using twinx()
I
keep getting error message “malformed header from script. Bad
header= is masked in one or more l: test.cgi” when I do two bar
charts on two axes. if I do one bar chart and one line chart, I
wouldnt get the error.
if I refresh the web page, the chart would show up.
the following is my code.

    ...
    ax = self.fig.add_axes( self.rectMain, axisbg=self.axesBG)
    ticks = self.setTickInterval( 10, 0, buybackDataobj.sharesMax)

    ind = na.array(range(len(

buybackDataobj.quarters)))
majorFormatter = FormatStrFormatter(’%2.1f’)
ax.yaxis.set_major_locator(MultipleLocator( ticks ) )

    ax.yaxis.set_major_formatter(majorFormatter)

     bar(ind, buybackDataobj.shares, self.barwidth, color=self.draw.color['DarkGreen'] ) 
    
    t = arange(0, float(buybackDataobj.sharesMax), ticks )
    ax.set_ylim(0, buybackDataobj.sharesMax * 1.1)

    ax.set_xlim(0, ind[-1] + self.barwidth*2)
    ax.set_ylabel("Value Bought " + buybackDataobj.scale, fontsize = self.fontsize )

    ax.set_xticks(ind + self.barwidth)

    ax.set_xticklabels( buybackDataobj.quarters, fontsize = self.fontsize)

    setp( ax.get_xticklabels(), rotation = self.rotation, horizontalalignment='center', family=

‘sans-serif’, fontsize = self.xaxisfs )

         if buybackDataobj.charttype == 'sells':

            ax2 = twinx()
            #ax2.plot(ind +

self.barwidth/2, buybackDataobj.sells, ls=’-’, marker =’.’, ms=11,
c=’#FF3300’) // I wouldnt get the error message if I do this
plot

            bar(ind + self.barwidth, buybackDataobj.sells,

self.barwidth, color=’#FF3300’ ) // malformed header from script. Bad
header= is masked in one or more l: test.cgi
ax2.set_xticklabels(buybackDataobj.quarters, visible=False )

            ax2.set_ylim(buybackDataobj.sellsMin * 0.75, buybackDataobj.sellsMax * 1.1)

ax2.set_ylabel(“Insider Selling $” + buybackDataobj.sellsScale,
verticalalignment=‘center’, fontsize = self.fontsize)

            setp( ax2.get_yticklabels(), rotation = 0,

horizontalalignment=‘left’, family=‘sans-serif’, fontsize=self.fontsize
)

···

On Mon, Apr 6, 2009 at 3:44 PM, Eric Firing <efiring@…202…> wrote:

P.Romero wrote:

Is it possible to create a colorbar with different scales on each side?

Example:

a temperature colorbar with celcius values on the left side and

farenheit values on the right side.

If so, how could this be done?

A colorbar is just an axes object with some customization of the ticks

and labels, and with a pcolor plot inside. You could get your second

scale using a technique similar to the twinx and twiny Axes methods; you

can then use set_xlim or set_ylim so that the Fahrenheit range on the

new axes matches the Celcius range on the old one.

To get started, look at the source for the twinx/twiny methods.

Eric

Please help,

Thanks,

P.Romero



This SF.net email is sponsored by:

High Quality Requirements in a Collaborative Environment.

Download a free trial of Rational Requirements Composer Now!

http://p.sf.net/sfu/www-ibm-com



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


This SF.net email is sponsored by:

High Quality Requirements in a Collaborative Environment.

Download a free trial of Rational Requirements Composer Now!

http://p.sf.net/sfu/www-ibm-com


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

j bai wrote:

Hi, P.Romero,
Please let me know if you get this working. I am trying to do the same type of 2 axes bar chart. but I got error message. I am using regular bar (). the following is the email i sent a week ago. Eric, I did use the twinx(), but it gave errors.
thanks in advance.

Hi, everyone, I am a matplotlib beginner. I am trying to do a chart with 2 y axes using twinx()
I keep getting error message "malformed header from script. Bad header= is masked in one or more l: test.cgi" when I do two bar charts on two axes. if I do one bar chart and one line chart, I wouldnt get the error. if I refresh the web page, the chart would show up. the following is my code.

        ...
        ax = self.fig.add_axes( self.rectMain, axisbg=self.axesBG)
        ticks = self.setTickInterval( 10, 0, buybackDataobj.sharesMax)
        ind = na.array(range(len(
buybackDataobj.quarters)))
        majorFormatter = FormatStrFormatter('%2.1f')
        ax.yaxis.set_major_locator(MultipleLocator( ticks ) )
        ax.yaxis.set_major_formatter(majorFormatter)
         bar(ind, buybackDataobj.shares, self.barwidth, color=self.draw.color['DarkGreen'] )

Try making that ax.bar(...)

                t = arange(0, float(buybackDataobj.sharesMax), ticks )
        ax.set_ylim(0, buybackDataobj.sharesMax * 1.1)
        ax.set_xlim(0, ind[-1] + self.barwidth*2)
        ax.set_ylabel("Value Bought " + buybackDataobj.scale, fontsize = self.fontsize )
         ax.set_xticks(ind + self.barwidth)
         ax.set_xticklabels( buybackDataobj.quarters, fontsize = self.fontsize)
        setp( ax.get_xticklabels(), rotation = self.rotation, horizontalalignment='center', family=
'sans-serif', fontsize = self.xaxisfs )

             if buybackDataobj.charttype == 'sells':

                ax2 = twinx()
                #ax2.plot(ind + self.barwidth/2, buybackDataobj.sells, ls='-', marker ='.', ms=11, c='#FF3300') // I wouldnt get the error message if I do this plot

                bar(ind + self.barwidth, buybackDataobj.sells, self.barwidth, color='#FF3300' ) // malformed header from script. Bad header= is masked in one or more l: test.cgi

And make that one ax2.bar(...).

It sounds like you have a combined mpl and cgi problem here; maybe an exception in mpl is triggering a cgi error. "malformed header from script" is not coming from mpl. "is masked in one or more" probably is, but you need to see the whole traceback to find out what the problem is.

So as a matter of strategy, separate the mpl from the cgi; make sure your script runs without error in standalone mode. Stick to purely or mostly OO style. You probably want to start with something like

import matplotlib
matplotlib.use("agg")
import pyplot as plt # e.g. if you want to use "fig = plt.figure()"

This makes sure you are using a non-interactive backend.

See http://matplotlib.sourceforge.net/faq/howto_faq.html#matplotlib-in-a-web-application-server

Eric

···

                ax2.set_xticklabels(buybackDataobj.quarters, visible=False )
                ax2.set_ylim(buybackDataobj.sellsMin * 0.75, buybackDataobj.sellsMax * 1.1)
                ax2.set_ylabel("Insider Selling $" + buybackDataobj.sellsScale, verticalalignment='center', fontsize = self.fontsize)

                setp( ax2.get_yticklabels(), rotation = 0, horizontalalignment='left', family='sans-serif', fontsize=self.fontsize )
           
.............

On Mon, Apr 6, 2009 at 3:44 PM, Eric Firing <efiring@…202… > <mailto:efiring@…202…>> wrote:

    P.Romero wrote:
     > Is it possible to create a colorbar with different scales on each
    side?
     >
     > Example:
     >
     > a temperature colorbar with celcius values on the left side and
     > farenheit values on the right side.
     >
     > If so, how could this be done?

    A colorbar is just an axes object with some customization of the ticks
    and labels, and with a pcolor plot inside. You could get your second
    scale using a technique similar to the twinx and twiny Axes methods; you
    can then use set_xlim or set_ylim so that the Fahrenheit range on the
    new axes matches the Celcius range on the old one.

    To get started, look at the source for the twinx/twiny methods.

    Eric

     >
     > Please help,
     >
     > Thanks,
     >
     > P.Romero
     >
    ------------------------------------------------------------------------
     >
    ------------------------------------------------------------------------------
     > This SF.net email is sponsored by:
     > High Quality Requirements in a Collaborative Environment.
     > Download a free trial of Rational Requirements Composer Now!
     > http://p.sf.net/sfu/www-ibm-com
     >
    ------------------------------------------------------------------------
     >
     > _______________________________________________
     > Matplotlib-users mailing list
     > Matplotlib-users@lists.sourceforge.net
    <mailto:Matplotlib-users@lists.sourceforge.net>
     > https://lists.sourceforge.net/lists/listinfo/matplotlib-users

    ------------------------------------------------------------------------------
    This SF.net email is sponsored by:
    High Quality Requirements in a Collaborative Environment.
    Download a free trial of Rational Requirements Composer Now!
    http://p.sf.net/sfu/www-ibm-com
    _______________________________________________
    Matplotlib-users mailing list
    Matplotlib-users@lists.sourceforge.net
    <mailto:Matplotlib-users@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com

------------------------------------------------------------------------

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