-1

I am a new programmer. It is not my job but i want to learn python. I am a Windows 10 user and I am using the folllowing programs: Python 3.8 Gtk+ Glade Gnuplot Pycharm. I have installed the first 4 programs by using msys2 and Pycharm as standalone.

I want to add gnuplot chart to the gui by using glade. Also i couldn't show the gnuplot to the Pycharm. It does not know the "import Gnuplot" command. Can anyone help me?

onur
  • 1
  • 2

2 Answers2

0

I think you need to import the module using this instead:

import PyGnuplot

Or possibly

import gnuplot-py

I see examples both ways.

gph
  • 1,045
  • 8
  • 25
  • I have tried the first one and it works. Thanks. Why gnuplot is not usable directly and we are adding a package from Pycharm? Also there are other packages for gnuplot. What are the differences? – onur Dec 07 '20 at 16:55
  • I need help for gnuplot plotting on glade generated gui. – onur Dec 07 '20 at 17:00
  • Sorry, I'm not familiar with this package. My answer was based on similar experiences where the module you import doesn't match what you install – gph Dec 07 '20 at 17:40
0

Welcome to programming! It's always great to see new people learning Python.

The error message you're seeing might be due to PyCharm not recognizing the Gnuplot package. It seems you are trying to import Gnuplot with the command import Gnuplot. Instead, you should use the command import PyGnuplot.

Let's consider a simple example of how to use PyGnuplot for plotting and fitting a function. This might help you better understand the library and its syntax:

First, we need to import the necessary libraries:

from PyGnuplot import gp
import numpy as np

Next, we create a new figure instance:

fig1 = gp()
fig1.default_term = 'wxt'

Now, let's generate some data to plot:

x = np.linspace(0, 20, 1001)
yn = np.random.randn(1001)/10
y = np.sin(x)
data = [x, y+yn]

In this case, we're generating x as a sequence of evenly spaced numbers from 0 to 20. The y values are a noisy sine wave. The yn variable is used to add some random noise to the y values to make the data look more like real-world data.

Next, let's define a function to fit to our data:

func = 'y(x) = a + b*cos(x + c)'  

This is a simple cosine function that we'll try to fit to our sine wave data. The a, b, and c are parameters of the function that will be adjusted to best fit the data.

Now, let's fit our function to the data:

(a, b, c), report = fig1.fit2d(data, func, via='a,b,c', limit=1e-9)

The fit2d function takes our data and function, and adjusts the parameters a, b, and c to minimize the difference between the function and the data. The limit argument specifies the stopping criterion for the fitting process.

Finally, let's plot the data and the fitted function:

fig1.save(data, "tmp.dat")
fig1.a('plot "tmp.dat" w lp')
fig1.a('replot y(x)')

This will first save the data to a file called "tmp.dat", then plot this data using points (lp stands for "linespoints"). The last line replots the fitted function on top of the data.

I hope this helps you get started with PyGnuplot! Please let me know if you have any further questions.

Restello
  • 1
  • 2