Wednesday, August 1, 2012

Re: How to print a graph

Great thanks...

   I found this function... it seems complicated, but it is kind of working... I hope that I can include it in a my web page...

  # file charts.py  def simple(request):      import random      import django      import datetime            from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas      from matplotlib.figure import Figure      from matplotlib.dates import DateFormatter        fig=Figure()      ax=fig.add_subplot(111)      x=[]      y=[]      now=datetime.datetime.now()      delta=datetime.timedelta(days=1)      for i in range(10):          x.append(now)          now+=delta          y.append(random.randint(0, 1000))      ax.plot_date(x, y, '-')      ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))      fig.autofmt_xdate()      canvas=FigureCanvas(fig)      response=django.http.HttpResponse(content_type='image/png')      canvas.print_png(response)      return response

On Wed, Aug 1, 2012 at 3:31 PM, Daniel Molina Wegener <dmw@coder.cl> wrote:
On 01/08/12 15:19, Peregil wrote:
I need to have the graphic on a web page... as soon as a user hit summit...

  If you need to draw a graph, you can try the pygraphviz.

  If you need to plot a chart, you can matplotlib, if that is not
so easy to implement, you can try using django google charts packages:

  http://pypi.python.org/pypi/django-googlecharts/1.0-alpha-1

  http://pypi.python.org/pypi/django-google-charts/0.1.1




On Wed, Aug 1, 2012 at 3:16 PM, william ratcliff
<william.ratcliff@gmail.com <mailto:william.ratcliff@gmail.com>> wrote:

    As a quick hack, you could generate a postscript file using
    savefig().   Then, you could print that from the commandline to a
    local printer--If they don't need a physical printout, I would
    generate a pdf file and serve it to them and let them print it.   If
    I figure out how to print directly using the printer dialog, I'll
    let you know...

    William


    On Wed, Aug 1, 2012 at 2:05 PM, Peregil <peregilx@gmail.com
    <mailto:peregilx@gmail.com>> wrote:

             it is an intranet, and I don't have any restrictions
        using JavaScript... abd I am using matplotlib... I thing it is
        the only way to save a file and put it on the web page...



        On Wed, Aug 1, 2012 at 1:59 PM, william ratcliff
        <william.ratcliff@gmail.com <mailto:william.ratcliff@gmail.com>>

        wrote:

            What are you using for your plotting package?  Matplotlib?
            I think that this will show the plot (on the server
            machine)--the easiest thing I can think of for now (assuming
            that you are using matplotlib) is to generate a pdf and send
            them the file.   I haven't tried printing directly--is this
            intranet, or external facing?  Do you have any restrictions
            on using javascript?

            William


            On Wed, Aug 1, 2012 at 12:58 PM, Peregil <peregilx@gmail.com
            <mailto:peregilx@gmail.com>> wrote:

                a user to print one

                I did this in python, but throws an error in django when
                I tried to run it... I have seen some examples of saving
                an image, but I would like to avoid that since I don't
                want to open and close a file...

                let me know if you have any idea....

                thanks

                Python program:


                def drawPlot(arrayGene1, arrayGene2):
                     message = ''
                     (m,b) = polyfit(arrayGene1,arrayGene2,1)
                     yp    = polyval([m,b],arrayGene1)
                     xlable('Gene 1')
                     ylable('Gene 2')
                     title('Correlation Graph')
                     plot(arrayGene1, yp)
                     scatter(arrayGene1,arrayGene2,marker='>')
                     show()
                     return(message)



                On Wed, Aug 1, 2012 at 12:21 PM, william ratcliff
                <william.ratcliff@gmail.com
                <mailto:william.ratcliff@gmail.com>> wrote:

                    Do you need to display a graph, or allow the user to
                    print one?

                    On Wed, Aug 1, 2012 at 12:06 PM, Peregil
                    <peregilx@gmail.com <mailto:peregilx@gmail.com>> wrote:

                        The information comes from a database, which I
                        got it with a problem. However, I need to show a
                        graph as well.

                        Please let me know any suggestions...

                        thanks and have great day.

                        --
                        You received this message because you are
                        subscribed to the Google Groups "Django users"
                        group.
                        To post to this group, send email to
                        django-users@googlegroups.com
                        <mailto:django-users@googlegroups.com>.

                        To unsubscribe from this group, send email to
                        django-users+unsubscribe@googlegroups.com
                        <mailto:django-users%2Bunsubscribe@googlegroups.com>.

                        For more options, visit this group at
                        http://groups.google.com/group/django-users?hl=en.


                    --
                    You received this message because you are subscribed
                    to the Google Groups "Django users" group.
                    To post to this group, send email to
                    django-users@googlegroups.com
                    <mailto:django-users@googlegroups.com>.

                    To unsubscribe from this group, send email to
                    django-users+unsubscribe@googlegroups.com
                    <mailto:django-users%2Bunsubscribe@googlegroups.com>.

                    For more options, visit this group at
                    http://groups.google.com/group/django-users?hl=en.


                --
                You received this message because you are subscribed to
                the Google Groups "Django users" group.
                To post to this group, send email to
                django-users@googlegroups.com
                <mailto:django-users@googlegroups.com>.

                To unsubscribe from this group, send email to
                django-users+unsubscribe@googlegroups.com
                <mailto:django-users%2Bunsubscribe@googlegroups.com>.

                For more options, visit this group at
                http://groups.google.com/group/django-users?hl=en.


            --
            You received this message because you are subscribed to the
            Google Groups "Django users" group.
            To post to this group, send email to
            django-users@googlegroups.com
            <mailto:django-users@googlegroups.com>.

            To unsubscribe from this group, send email to
            django-users+unsubscribe@googlegroups.com
            <mailto:django-users%2Bunsubscribe@googlegroups.com>.

            For more options, visit this group at
            http://groups.google.com/group/django-users?hl=en.


        --
        You received this message because you are subscribed to the
        Google Groups "Django users" group.
        To post to this group, send email to
        django-users@googlegroups.com
        <mailto:django-users@googlegroups.com>.

        To unsubscribe from this group, send email to
        django-users+unsubscribe@googlegroups.com
        <mailto:django-users%2Bunsubscribe@googlegroups.com>.

        For more options, visit this group at
        http://groups.google.com/group/django-users?hl=en.


    --
    You received this message because you are subscribed to the Google
    Groups "Django users" group.
    To post to this group, send email to django-users@googlegroups.com
    <mailto:django-users@googlegroups.com>.

    To unsubscribe from this group, send email to
    django-users+unsubscribe@googlegroups.com
    <mailto:django-users%2Bunsubscribe@googlegroups.com>.

    For more options, visit this group at
    http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

Best regards,
--
Daniel Molina Wegener <dmw [at] coder [dot] cl>
System Programmer & Web Developer
Phone: +56 (2) 979-0278 | Blog: http://coder.cl/


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment