OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I add custom xtics for a python gnuplotlib plot?

  • Thread starter Thread starter Eric G
  • Start date Start date
E

Eric G

Guest
I want to add custom tick labels on the x-axis using the python gnuplotlib.

I have tried (using jupyterlab):

Code:
import numpy as np
import gnuplotlib as gp

xtics_positions = [0, 2, 4, 6, 8]
xtics_labels = ["zero", "two", "four", "six", "eight"]
xtics = [(label, pos) for label, pos in zip(xtics_labels, xtics_positions)]

datapoints = np.array([ 0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0, 11,  5,  5,  2, 21,  1, 21,  0,  8, 62, 56,  0,  0,  0,  6,  3, 32,  7, 17,  1,  6, 10, 12,  0, 21, 11,  6, 14,  1, 15, 25, 30, 17, 11,  6,  4,  0])
gp.plot(datapoints, xtics = xtics)

but that does not work.

If I call gp.plot(datapoints), the plot produced is:

plot
<p>I want to add custom tick labels on the x-axis using the python gnuplotlib.</p>
<p>I have tried (using jupyterlab):</p>
<pre><code>import numpy as np
import gnuplotlib as gp

xtics_positions = [0, 2, 4, 6, 8]
xtics_labels = ["zero", "two", "four", "six", "eight"]
xtics = [(label, pos) for label, pos in zip(xtics_labels, xtics_positions)]

datapoints = np.array([ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 5, 5, 2, 21, 1, 21, 0, 8, 62, 56, 0, 0, 0, 6, 3, 32, 7, 17, 1, 6, 10, 12, 0, 21, 11, 6, 14, 1, 15, 25, 30, 17, 11, 6, 4, 0])
gp.plot(datapoints, xtics = xtics)
</code></pre>
<p>but that does not work.</p>
<p>If I call <code>gp.plot(datapoints)</code>, the plot produced is:</p>
<p><a href="https://i.sstatic.net/XWjD9V1c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XWjD9V1c.png" alt="plot" /></a></p>
 

Latest posts

Top