matplotlib
does not seem to accept values other than integer and list of the form (start, N) in my python compiler. Though it accepts floating values (which is supposed to approximately put the markers equally spaced along the line), it seems to be truncating the decimal part and uses the integral part as the argument. For all other input formats, it throws error. I am using Python 2.7.3 and matplotlib 1.1.1 in ubuntu 12.04 LTS. What is going wrong?
I take a small code as an example from the thread: Plotting a curve with equidistant (arc-length) markers.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10*np.pi, 1000)
y = np.sin(x*2) + np.sin(x + 1)
plt.plot(x, y, marker='o', markevery=xx)
plt.show()
float value less than
1.0
:markevery=0.05
Traceback (most recent call last): File "try2.py", line 10, in <module> plt.savefig('try2.pdf') File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 471, in savefig return fig.savefig(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1185, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2021, in print_figure **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1789, in print_pdf return pdf.print_pdf(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2186, in print_pdf self.figure.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 898, in draw func(*args) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1997, in draw a.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 535, in draw vertices = tpath.vertices[startind::stride] ValueError: slice step cannot be zero
markevery=slice(start, end, N)
, every N-th marker, starting at point start, upto but not including point end, will be plotted:markevery=slice(200,300,20)
Traceback (most recent call last): File "try2.py", line 10, in <module> plt.savefig('try2.pdf') File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 471, in savefig return fig.savefig(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1185, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2021, in print_figure **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1789, in print_pdf return pdf.print_pdf(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2186, in print_pdf self.figure.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 898, in draw func(*args) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1997, in draw a.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 528, in draw startind, stride = markevery ValueError: too many values to unpack
markevery=[i, j, m, n]
, only markers at points i, j, m, and n will be plotted:markevery=[200,250,300,350]
Traceback (most recent call last): File "try2.py", line 10, in <module> plt.savefig('try2.pdf') File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 471, in savefig return fig.savefig(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1185, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2021, in print_figure **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1789, in print_pdf return pdf.print_pdf(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2186, in print_pdf self.figure.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 898, in draw func(*args) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1997, in draw a.draw(renderer) File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 528, in draw startind, stride = markevery ValueError: too many values to unpack
matplotlib
. I am running 1.5.3 and the example works with non-integer values ofmarkevery
– DavidG Nov 11 '16 at 9:50markevery=slice(200,300,20)
andmarkevery=[200,250,300,350]
? – mohan_das Nov 11 '16 at 10:37