I've been using Matplotlib for a couple of years, and generally speaking, it works OK for me. There are however a couple of exceptions. Firstly, it sometimes creates so many ticks on the Y axis that it is impossible to read any of them, and secondly, it sometimes produces what looks like a sensible chart, until you check the data. Often, it puts the ticks in a seemingly random order (rather than lowest value at the bottom, highest at the top), and sometimes, the chart line is right (i.e. what the data suggests it should be), other times it seems to bare scant resemblance to the Y axis values.
Consider the attached images. The first was generated using matplotlib, the second with Open Office
In this case, the Y ticks aren't in the right order, but the plotted line follows the marked values. As you can see it starts at 6811, and the first peak is 6813, both show this, but the latter chart rightly has 6813 above 6812 on the Y axis.
I'm running the latest version (3.8.4), but this is a problem that I've seen with earlier versions.
I'm getting the data from a CSV file, and at first it seemed that when the data is in the first few columns, the charts always seemed right, it is when it comes from the right hand end of a long line that the problems seem to arise. However, I took a data file and fed it through awk to just give me the first and last columns, and I get the same problem with a 2 column file that I get with a 13 column file (picking columns 1 and 13). It looks as though it doesn't like the data, rather than where it lies in the CSV file.
What I'm using is this (with some surplus stuff stripped out for brevity)
The data looks like this (trimmed for brevity full data set available if you want it)
Suggestions welcome on where to look next.
Thanks
Adrian
Consider the attached images. The first was generated using matplotlib, the second with Open Office
In this case, the Y ticks aren't in the right order, but the plotted line follows the marked values. As you can see it starts at 6811, and the first peak is 6813, both show this, but the latter chart rightly has 6813 above 6812 on the Y axis.
I'm running the latest version (3.8.4), but this is a problem that I've seen with earlier versions.
I'm getting the data from a CSV file, and at first it seemed that when the data is in the first few columns, the charts always seemed right, it is when it comes from the right hand end of a long line that the problems seem to arise. However, I took a data file and fed it through awk to just give me the first and last columns, and I get the same problem with a 2 column file that I get with a 13 column file (picking columns 1 and 13). It looks as though it doesn't like the data, rather than where it lies in the CSV file.
What I'm using is this (with some surplus stuff stripped out for brevity)
Code:
import matplotlib.pyplot as pltimport matplotlib.ticker as tickerimport csvimport sysimport timefrom matplotlib.ticker import FormatStrFormatterif len(sys.argv) < 6: raise ValueError ('Insufficient Parameters, requires:\nData source\nDate (\"today\" or yymmdd)\nChart type\nDestination Directory\nColumn number')infile = sys.argv[1]when = sys.argv[2]what = sys.argv[3]directory = sys.argv[4]data_column = int(sys.argv[5])date = []y = []if when == 'today': hour = int(time.strftime ("%H")) if hour < 6: ticklist = [0, 60, 120, 180, 240, 300] elif hour < 12: ticklist = [0, 120, 240, 360, 480, 600] elif hour < 18: ticklist = [0, 180, 360, 540, 720, 900] else: ticklist = [0, 240, 480, 720, 960, 1200, 1440]else: ticklist = [0, 240, 480, 720, 960, 1200, 1440]if what == "ldf_stats": with open (infile, 'r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: dt = row[0] time = dt[8:10] + ":" + dt[10:] date.append(time) y.append(row[data_column]) fig = plt.figure() ax = fig.add_axes([.1, .2, .7, .7]) ax.xaxis.set_major_locator(ticker.FixedLocator(ticklist)) ax.plot(date, y, label='Card Usage') plt.xticks(rotation=90) plt.xlabel('Time') plt.ylabel('M Blocks') plt.legend() plt.savefig ('/home/pi/Pictures/ldf_stats_' + when + '.png')
Code:
202404100000,6811202404100001,6811202404100002,6811202404100003,6811202404100004,6811202404100005,6811202404100006,6811202404100007,6811202404100008,6811202404100009,6811
Thanks
Adrian
Statistics: Posted by ffoiled — Thu Apr 11, 2024 4:28 pm