Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:44:10+00:00 2026-05-22T01:44:10+00:00

I am trying to draw a graph of some data I pull out of

  • 0

I am trying to draw a graph of some data I pull out of a MySQL database through python with gnuplot and gnuplot.py.
I read the latest 10 lines of data from the MySQL database and store them in a temp file which is supposed to be read by gnuplot. I can do this the manual way by setting through the terminal, but I simply can’t see how I should load the file into gnuplot through python.
If you can show me an easier way to do this, or simply a way to do it at all, I would be very grateful.

import MySQLdb
import Gnuplot

datafile = open('data', 'w+r')

gp = Gnuplot.Gnuplot(persist=1)
gp('set style data lines')
gp('set term png')
gp('set output "escan_graph.png"')
gp('set datafile separator "|"')

db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="zig")
cursor = db.cursor()

cursor.execute("select * from escan_data")

numrows = int(cursor.rowcount) #get the count of total
# get and display one row at a time

if numrows > 10:
        start = numrows-10
else:
        start = 0

for x in range(start,numrows):
        row = cursor.fetchone()
        print row[0], row[1]
        datafile.write(str(row[0]) + "|" + str(row[1]) + "\n")



databuff = Gnuplot.Data(datafile.read(), title="test")


gp.plot(databuff)

row[0] is the x-axis and row[1] is y-axis.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:44:11+00:00Added an answer on May 22, 2026 at 1:44 am

    This doesn’t work because after you write the file object’s cursor is at the end of the file. If you want to really do this (you are better off not writing the data to a file at all), you need to move the cursor back to the beginning of the file:

    datafile.seek(0)
    

    Now you can read() from the beginning of the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw some simples lines with the iPhone/Touch SDK. I'd like to
so I am trying to draw some grid lines that in landscape go all
I am trying to draw a graph showing search prefixes using twopi. I have
I am trying to draw a series of rectangles using OpenGL but some of
I have some code at the moment to draw a graph based on the
I am trying to draw a graph using Graphviz, but I need to add
i'm trying to draw a Graph with a user-friendly timeline having every day/week (to
Hi I am trying to draw one line graph and for that I am
I was trying a script to draw graph paper like grids on the canvas
I'm trying to draw a graph on an ASP webpage. I'm hoping an API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.