Folium Heatmap Unexpected Weighted Results - python
I am attempting to use Folium to display a map of After Renovation Values for houses in a certain area. The higher the ARV, the "hotter" I want that area of the map.
I am trying to take advantage of Folium's weighted heatmap, however, random points seem to be way hotter than others despite having a lower ARV (and thus lower weighted value). When I use a lot of points for my heatmap (>1000) only one point is "hot" and the rest are cold. See image.
I am normalizing the ARV values between 0.5 and 1.5. I have tried other normalized values with no success.
In the screenshot, note that there are many points on this map with a higher ARV value and heatmap weighted value. Also there are other areas of the map with more points clustered together. So I have no idea why this one is the only one that is hot.
Below is some sample data.
import pandas as pd
import folium
from folium import Map
from folium.plugins import HeatMap
import csv_helper
# Custom function that converts a CSV with Address, Latitude, Longitude, ARV to python List
csv_list = csv_helper.csv_to_list('arvs.csv')
# Normalized min & max
new_min = 0.5
new_max = 1.5
hmap = Map(location=[41.496551, -81.65133], zoom_start=100)
# Add markers to map
for address in csv_list:
arv = int(address['ARV'])
# newvalue= (max'-min')/(max-min)*(value-min)+min'.
arv_normalized = round(float((new_max-new_min)/(500000-40000)*(arv-40000)+new_min),3)
# Show ARV value and normalized value (for heatmap) for debugging purposes
tooltip = "$" + address['ARV']
tooltip += " " + str(arv_normalized)
folium.Circle(
[address['Latitude'], address['Longitude']], popup="<i></i>", tooltip=tooltip, radius=150
).add_to(hmap)
# -------------------------------------------------
# Create heatmap with normalized ARV values
final_list = []
for address in csv_list:
arv = int(address['ARV'])
# newvalue= (max'-min')/(max-min)*(value-min)+min'.
arv_normalized = round(float((new_max-new_min)/(500000-40000)*(arv-40000)+new_min),3)
final_list.append((float(address['Latitude']), float(address['Longitude']), arv_normalized))
# ---------------------------------------
final_map = HeatMap(
final_list,
min_opacity=0.2,
radius=40,
blur=40,
)
hmap.add_child(final_map)
hmap.save('index.html')
ARV,Latitude,Longitude
80000,35.20271,-90.008334
120000,41.391633,-81.522691
130000,41.509003,-81.553549
250000,35.058779,-89.881985
160000,41.439312,-81.922154
410000,41.521241,-81.405547
350000,41.388637,-81.414451
360000,41.473301,-81.519901
264000,35.014625,-89.81703
175000,41.513541,-81.536019
410000,41.521241,-81.405547
180000,34.996242,-89.838076
110000,41.496551,-81.65133
110000,41.496551,-81.65133
140000,41.453832,-81.792491
230000,35.058779,-89.881985
150000,41.481158,-81.747563
360000,41.476918,-81.855462
130000,41.526998,-81.504134
350000,41.488054,-81.929447
850000,35.124245,-89.894052
260000,41.496551,-81.65133
400000,41.557968,-81.451966
240000,41.425264,-81.953059
110000,40.788578,-81.416775
140000,41.498209,-81.5627
120000,41.411274,-81.584893
250000,41.378911,-81.754235
250000,41.489806,-81.51235
100000,41.395767,-81.535133
40000,40.783719,-81.379159
130000,41.395311,-81.704656
140000,41.513541,-81.536019
65000,41.449614,-81.596527
160000,35.112125,-89.954644
70000,41.724602,-81.250865
120000,41.496551,-81.65133
120000,41.536174,-81.536244
75000,41.467058,-82.163095
155000,41.395311,-81.704656
500000,41.522976,-81.409499
250000,41.510947,-81.48978
165000,41.463768,-81.555838
230000,41.399833,-81.948991
270000,41.399833,-81.948991
100000,41.56134,-81.536752
260000,41.476192,-81.787702
270000,41.509563,-81.597207
145000,41.409494,-81.732268
250000,41.481919,-81.891249
130000,41.610679,-81.494706
360000,35.119919,-89.986065
370000,41.485596,-81.968291
240000,41.459678,-81.562217
480000,41.566412,-81.460469
135000,41.412794,-81.550415
390000,41.33429,-81.650159
390000,41.33429,-81.650159
90000,41.40014,-81.591994
110000,41.403025,-81.510372
250000,41.496551,-81.65133
165000,41.417272,-81.708537
230000,35.038678,-89.826112
170000,41.360592,-81.784523
230000,41.396157,-81.791135
420000,41.429342,-81.410058
310000,41.331445,-81.788
160000,41.314045,-81.831505
330000,41.347437,-81.715494
120000,41.434043,-81.713272
130000,41.389556,-81.742872
400000,41.313209,-81.827588
180000,35.029085,-89.830267
80000,41.395767,-81.535133
310000,41.313209,-81.827588
40000,35.179305,-89.987687
60000,41.460838,-81.721954
220000,35.009043,-89.803944
65000,41.517454,-81.659181
200000,41.402621,-81.666393
350000,41.475409,-81.831745
300000,41.432224,-81.941826
170000,41.405186,-81.71861
90000,41.478149,-81.649167
120000,41.442856,-81.774558
145000,41.444031,-81.813938
155000,41.424741,-81.641074
35000,41.44021,-81.640585
180000,35.048025,-89.874334
190000,41.397042,-81.792927
50000,41.569235,-81.553251
180000,41.50035,-81.569165
55000,41.518024,-81.625218
55000,41.490536,-81.76919
95000,39.821712,-86.081666
370000,41.481909,-81.936075
70000,41.607244,-81.503932
95000,39.821863,-86.081666
95000,41.44741,-81.550367
320000,41.473999,-81.847547
70000,35.152693,-89.959701
155000,41.457457,-81.552897
280000,41.48613,-81.53254
80000,35.059993,-90.089206
300000,41.432411,-81.476042
200000,41.481345,-81.713879
120000,41.496551,-81.65133
500000,41.454979,-81.933205
150000,41.496551,-81.65133
130000,41.595095,-81.532663
100000,41.433458,-81.69937
80000,35.112125,-89.954644
90000,41.431867,-81.776982
140000,41.437502,-81.719623
140000,41.437502,-81.719623
50000,41.40909,-81.727864
120000,41.446436,-81.54706
255000,41.474547,-81.520539
114000,41.447594,-81.786672
146000,41.396294,-81.719042
205000,41.496551,-81.65133
61000,41.460998,-81.664012
161000,41.526099,-81.480258
139000,41.616156,-81.516354
72000,35.261568,-90.03766
262000,41.388719,-81.655214
236000,41.42287,-81.880106
140000,41.496551,-81.65133
250000,41.481431,-81.816511
112000,41.393322,-81.568783
58000,41.474515,-81.615786
152000,35.160754,-89.941566
57000,41.45761,-81.711104
286000,41.526976,-81.625285
254000,41.502558,-81.591683
144000,41.565275,-81.522166
168672,41.496551,-81.65133
158000,41.515294,-81.480691
199000,35.145123,-89.923967
142000,41.407764,-81.705747
380000,41.515489,-81.498872
264000,41.459379,-81.546031
130000,41.59737,-81.519512
263000,41.470533,-81.856104
109000,41.616926,-81.489452
142000,41.496551,-81.65133
172000,41.468386,-81.797626
45000,41.445988,-81.637576
381000,41.479981,-81.796735
86000,41.451478,-81.570577
316000,35.141949,-89.89007
171000,41.340916,-81.67061
186000,41.527123,-81.488265
118000,41.390367,-81.857135
272000,41.493983,-81.580516
192000,41.474904,-81.790612
716000,41.497215,-81.577634
74000,41.455386,-81.644509
217000,41.474904,-81.790612
249000,41.54746,-81.464124
76000,41.401175,-81.591213
161000,35.01404,-89.842125
148000,41.458904,-81.718525
296000,41.474576,-81.510153
51000,41.496551,-81.65133
86000,41.534577,-81.563225
274000,41.331352,-82.079267
87000,41.408078,-81.550402
111000,41.495959,-81.646259
236000,41.473035,-81.924042
236000,41.473035,-81.924042
87000,41.408078,-81.550402
118000,41.453988,-81.554598
272000,41.478278,-81.71321
193000,41.389737,-81.806958
237000,41.469768,-81.839801
458000,41.461405,-81.501236
167000,41.495068,-81.550947
98000,41.461061,-81.705367
87000,41.528795,-81.620411
140000,41.416514,-81.522673
280000,35.113076,-89.939775
129000,41.462182,-81.770669
294000,41.468942,-81.818158
187000,41.496551,-81.65133
156000,41.496551,-81.65133
80000,41.538235,-81.620539
234000,41.340449,-81.724167
154000,41.539205,-81.504106
68000,41.458083,-81.60988
67000,41.598958,-81.528403
98000,41.456772,-81.586504
152000,35.197116,-89.81058
134000,41.441131,-81.72843
84000,41.520814,-81.629809
264000,41.51196,-81.578458
132000,41.457867,-81.772089
318000,41.601059,-81.544561
224000,41.305686,-81.724923
Related
store values and continue running function
I am using astropy to detect sources in an image. I am trying to write a function that will detect my sources, with an option of storing their coordinates in an array, and another option to plot the sources. This is my code: def SourceDetect(file, SIG, FWHM, THRESH, store = False, PlotStars = False): image = pf.open(file) im = image[0].data mean, median, std = sigma_clipped_stats(im, sigma=SIG) daofind = DAOStarFinder(fwhm = FWHM, threshold = THRESH * std) sources = daofind(im - median) positions = np.transpose((sources['xcentroid'], sources['ycentroid'])) if(store): return positions if(PlotStars): apertures = CircularAperture(positions, r = 6.) norm = ImageNormalize(stretch = SqrtStretch()) plt.imshow(im, cmap = 'Greys', origin = 'lower', norm = norm, interpolation = 'nearest') apertures.plot(color = 'blue', lw = 1.5, alpha = 1) for i in range(0, len(sources)): plt.text(sources[i]['xcentroid'], sources[i]['ycentroid'], i, color='black'); However when I run this code with both store and plot set to True only the store part of the function runs and I can't get it to plot unless I make store False. Is there a way to write this code where I will be able to have my coordinates stored and plotted?
Simple change order - first PlotStars, next store if PlotStars: # ... code ... if store: return positions and this will first display plot and later it exits function with value. But if you want first get value and later plot then you should run it two times - first only with store=True and later only with PlotStars=True
How to Create a Boxplot / Group Boxplot from [Min ,Q1 ,Q2 ,Q3 ,Max] in Python? [duplicate]
From what I can see, boxplot() method expects a sequence of raw values (numbers) as input, from which it then computes percentiles to draw the boxplot(s). I would like to have a method by which I could pass in the percentiles and get the corresponding boxplot. For example: Assume that I have run several benchmarks and for each benchmark I've measured latencies ( floating point values ). Now additionally, I have precomputed the percentiles for these values. Hence for each benchmark, I have the 25th, 50th, 75th percentile along with the min and max. Now given these data, I would like to draw the box plots for the benchmarks.
As of 2020, there is a better method than the one in the accepted answer. The matplotlib.axes.Axes class provides a bxp method, which can be used to draw the boxes and whiskers based on the percentile values. Raw data is only needed for the outliers, and that is optional. Example: import matplotlib.pyplot as plt fig, ax = plt.subplots() boxes = [ { 'label' : "Male height", 'whislo': 162.6, # Bottom whisker position 'q1' : 170.2, # First quartile (25th percentile) 'med' : 175.7, # Median (50th percentile) 'q3' : 180.4, # Third quartile (75th percentile) 'whishi': 187.8, # Top whisker position 'fliers': [] # Outliers } ] ax.bxp(boxes, showfliers=False) ax.set_ylabel("cm") plt.savefig("boxplot.png") plt.close() This produces the following image:
To draw the box plot using just the percentile values and the outliers ( if any ) I made a customized_box_plot function that basically modifies attributes in a basic box plot ( generated from a tiny sample data ) to make it fit according to your percentile values. The customized_box_plot function def customized_box_plot(percentiles, axes, redraw = True, *args, **kwargs): """ Generates a customized boxplot based on the given percentile values """ box_plot = axes.boxplot([[-9, -4, 2, 4, 9],]*n_box, *args, **kwargs) # Creates len(percentiles) no of box plots min_y, max_y = float('inf'), -float('inf') for box_no, (q1_start, q2_start, q3_start, q4_start, q4_end, fliers_xy) in enumerate(percentiles): # Lower cap box_plot['caps'][2*box_no].set_ydata([q1_start, q1_start]) # xdata is determined by the width of the box plot # Lower whiskers box_plot['whiskers'][2*box_no].set_ydata([q1_start, q2_start]) # Higher cap box_plot['caps'][2*box_no + 1].set_ydata([q4_end, q4_end]) # Higher whiskers box_plot['whiskers'][2*box_no + 1].set_ydata([q4_start, q4_end]) # Box box_plot['boxes'][box_no].set_ydata([q2_start, q2_start, q4_start, q4_start, q2_start]) # Median box_plot['medians'][box_no].set_ydata([q3_start, q3_start]) # Outliers if fliers_xy is not None and len(fliers_xy[0]) != 0: # If outliers exist box_plot['fliers'][box_no].set(xdata = fliers_xy[0], ydata = fliers_xy[1]) min_y = min(q1_start, min_y, fliers_xy[1].min()) max_y = max(q4_end, max_y, fliers_xy[1].max()) else: min_y = min(q1_start, min_y) max_y = max(q4_end, max_y) # The y axis is rescaled to fit the new box plot completely with 10% # of the maximum value at both ends axes.set_ylim([min_y*1.1, max_y*1.1]) # If redraw is set to true, the canvas is updated. if redraw: ax.figure.canvas.draw() return box_plot USAGE Using inverse logic ( code at the very end ) I extracted the percentile values from this example >>> percentiles (-1.0597368367634488, 0.3977683984966961, 1.0298955252405229, 1.6693981537742526, 3.4951447843464449) (-0.90494930553559483, 0.36916539612108634, 1.0303658700697103, 1.6874542731392828, 3.4951447843464449) (0.13744105279440233, 1.3300645202649739, 2.6131540656339483, 4.8763411136047647, 9.5751914834437937) (0.22786243898199182, 1.4120860286080519, 2.637650402506837, 4.9067126578493259, 9.4660357513550899) (0.0064696168078617741, 0.30586770128093388, 0.70774153557312702, 1.5241965711101928, 3.3092932063051976) (0.007009744579241136, 0.28627373934008982, 0.66039691869500572, 1.4772725266672091, 3.221716765477217) (-2.2621660374110544, 5.1901313713883352, 7.7178532139979357, 11.277744848353247, 20.155971739152388) (-2.2621660374110544, 5.1884411864079532, 7.3357079047721054, 10.792299385806913, 18.842012119715388) (2.5417888074435702, 5.885996170695587, 7.7271286220368598, 8.9207423361593179, 10.846938621419374) (2.5971767318505856, 5.753551925927133, 7.6569980004033464, 8.8161056254143233, 10.846938621419374) Note that to keep this short I haven't shown the outliers vectors which will be the 6th element of each of the percentile array. Also note that all usual additional kwargs / args can be used since they are simply passed to the boxplot method inside it : >>> fig, ax = plt.subplots() >>> b = customized_box_plot(percentiles, ax, redraw=True, notch=0, sym='+', vert=1, whis=1.5) >>> plt.show() EXPLANATION The boxplot method returns a dictionary mapping the components of the boxplot to the individual matplotlib.lines.Line2D instances that were created. Quoting from the matplotlib.pyplot.boxplot documentation : That dictionary has the following keys (assuming vertical boxplots): boxes: the main body of the boxplot showing the quartiles and the median’s confidence intervals if enabled. medians: horizonal lines at the median of each box. whiskers: the vertical lines extending to the most extreme, n-outlier data points. caps: the horizontal lines at the ends of the whiskers. fliers: points representing data that extend beyond the whiskers (outliers). means: points or lines representing the means. For example observe the boxplot of a tiny sample data of [-9, -4, 2, 4, 9] >>> b = ax.boxplot([[-9, -4, 2, 4, 9],]) >>> b {'boxes': [<matplotlib.lines.Line2D at 0x7fe1f5b21350>], 'caps': [<matplotlib.lines.Line2D at 0x7fe1f54d4e50>, <matplotlib.lines.Line2D at 0x7fe1f54d0e50>], 'fliers': [<matplotlib.lines.Line2D at 0x7fe1f5b317d0>], 'means': [], 'medians': [<matplotlib.lines.Line2D at 0x7fe1f63549d0>], 'whiskers': [<matplotlib.lines.Line2D at 0x7fe1f5b22e10>, <matplotlib.lines.Line2D at 0x7fe20c54a510>]} >>> plt.show() The matplotlib.lines.Line2D objects have two methods that I'll be using in my function extensively. set_xdata ( or set_ydata ) and get_xdata ( or get_ydata ). Using these methods we can alter the position of the constituent lines of the base box plot to conform to your percentile values ( which is what the customized_box_plot function does ). After altering the constituent lines' position, you can redraw the canvas using figure.canvas.draw() Summarizing the mappings from percentile to the coordinates of the various Line2D objects. The Y Coordinates : The max ( q4_end - end of 4th quartile ) corresponds to the top most cap Line2D object. The min ( q1_start - start of the 1st quartile ) corresponds to the lowermost most cap Line2D object. The median corresponds to the ( q3_start ) median Line2D object. The 2 whiskers lie between the ends of the boxes and extreme caps ( q1_start and q2_start - lower whisker; q4_start and q4_end - upper whisker ) The box is actually an interesting n shaped line bounded by a cap at the lower portion. The extremes of the n shaped line correspond to the q2_start and the q4_start. The X Coordinates : The Central x coordinates ( for multiple box plots are usually 1, 2, 3... ) The library automatically calculates the bounding x coordinates based on the width specified. INVERSE FUNCTION TO RETRIEVE THE PERCENTILES FROM THE boxplot DICT: def get_percentiles_from_box_plots(bp): percentiles = [] for i in range(len(bp['boxes'])): percentiles.append((bp['caps'][2*i].get_ydata()[0], bp['boxes'][i].get_ydata()[0], bp['medians'][i].get_ydata()[0], bp['boxes'][i].get_ydata()[2], bp['caps'][2*i + 1].get_ydata()[0], (bp['fliers'][i].get_xdata(), bp['fliers'][i].get_ydata()))) return percentiles NOTE: The reason why I did not make a completely custom boxplot method is because, there are many features offered by the inbuilt box plot that cannot be fully reproduced. Also excuse me if I may have unnecessarily explained something that may have been too obvious.
Here is an updated version of this useful routine. Setting the vertices directly appears to work for both filled boxes (patchArtist=True) and unfilled ones. def customized_box_plot(percentiles, axes, redraw = True, *args, **kwargs): """ Generates a customized boxplot based on the given percentile values """ n_box = len(percentiles) box_plot = axes.boxplot([[-9, -4, 2, 4, 9],]*n_box, *args, **kwargs) # Creates len(percentiles) no of box plots min_y, max_y = float('inf'), -float('inf') for box_no, pdata in enumerate(percentiles): if len(pdata) == 6: (q1_start, q2_start, q3_start, q4_start, q4_end, fliers_xy) = pdata elif len(pdata) == 5: (q1_start, q2_start, q3_start, q4_start, q4_end) = pdata fliers_xy = None else: raise ValueError("Percentile arrays for customized_box_plot must have either 5 or 6 values") # Lower cap box_plot['caps'][2*box_no].set_ydata([q1_start, q1_start]) # xdata is determined by the width of the box plot # Lower whiskers box_plot['whiskers'][2*box_no].set_ydata([q1_start, q2_start]) # Higher cap box_plot['caps'][2*box_no + 1].set_ydata([q4_end, q4_end]) # Higher whiskers box_plot['whiskers'][2*box_no + 1].set_ydata([q4_start, q4_end]) # Box path = box_plot['boxes'][box_no].get_path() path.vertices[0][1] = q2_start path.vertices[1][1] = q2_start path.vertices[2][1] = q4_start path.vertices[3][1] = q4_start path.vertices[4][1] = q2_start # Median box_plot['medians'][box_no].set_ydata([q3_start, q3_start]) # Outliers if fliers_xy is not None and len(fliers_xy[0]) != 0: # If outliers exist box_plot['fliers'][box_no].set(xdata = fliers_xy[0], ydata = fliers_xy[1]) min_y = min(q1_start, min_y, fliers_xy[1].min()) max_y = max(q4_end, max_y, fliers_xy[1].max()) else: min_y = min(q1_start, min_y) max_y = max(q4_end, max_y) # The y axis is rescaled to fit the new box plot completely with 10% # of the maximum value at both ends axes.set_ylim([min_y*1.1, max_y*1.1]) # If redraw is set to true, the canvas is updated. if redraw: ax.figure.canvas.draw() return box_plot
Here is a bottom-up approach where the box_plot is build up using matplotlib's vline, Rectangle, and normal plot functions def boxplot(df, ax=None, box_width=0.2, whisker_size=20, mean_size=10, median_size = 10 , line_width=1.5, xoffset=0, color=0): """Plots a boxplot from existing percentiles. Parameters ---------- df: pandas DataFrame ax: pandas AxesSubplot if to plot on en existing axes box_width: float whisker_size: float size of the bar at the end of each whisker mean_size: float size of the mean symbol color: int or rgb(list) If int particular color of property cycler is taken. Example of rgb: [1,0,0] (red) Returns ------- f, a, boxes, vlines, whisker_tips, mean, median """ if type(color) == int: color = plt.rcParams['axes.prop_cycle'].by_key()['color'][color] if ax: a = ax f = a.get_figure() else: f, a = plt.subplots() boxes = [] vlines = [] xn = [] for row in df.iterrows(): x = row[0] + xoffset xn.append(x) # box y = row[1][25] height = row[1][75] - row[1][25] box = plt.Rectangle((x - box_width / 2, y), box_width, height) a.add_patch(box) boxes.append(box) # whiskers y = (row[1][95] + row[1][5]) / 2 vl = a.vlines(x, row[1][5], row[1][95]) vlines.append(vl) for b in boxes: b.set_linewidth(line_width) b.set_facecolor([1, 1, 1, 1]) b.set_edgecolor(color) b.set_zorder(2) for vl in vlines: vl.set_color(color) vl.set_linewidth(line_width) vl.set_zorder(1) whisker_tips = [] if whisker_size: g, = a.plot(xn, df[5], ls='') whisker_tips.append(g) g, = a.plot(xn, df[95], ls='') whisker_tips.append(g) for wt in whisker_tips: wt.set_markeredgewidth(line_width) wt.set_color(color) wt.set_markersize(whisker_size) wt.set_marker('_') mean = None if mean_size: g, = a.plot(xn, df['mean'], ls='') g.set_marker('o') g.set_markersize(mean_size) g.set_zorder(20) g.set_markerfacecolor('None') g.set_markeredgewidth(line_width) g.set_markeredgecolor(color) mean = g median = None if median_size: g, = a.plot(xn, df['median'], ls='') g.set_marker('_') g.set_markersize(median_size) g.set_zorder(20) g.set_markeredgewidth(line_width) g.set_markeredgecolor(color) median = g a.set_ylim(np.nanmin(df), np.nanmax(df)) return f, a, boxes, vlines, whisker_tips, mean, median This is how it looks in action: import numpy as np import pandas as pd import matplotlib.pylab as plt nopts = 12 df = pd.DataFrame() df['mean'] = np.random.random(nopts) + 7 df['median'] = np.random.random(nopts) + 7 df[5] = np.random.random(nopts) + 4 df[25] = np.random.random(nopts) + 6 df[75] = np.random.random(nopts) + 8 df[95] = np.random.random(nopts) + 10 out = boxplot(df)
Python : Multiple Line\any form of graph by defining Matching column values with large datasets
Trying to Plot this Raw JSON data into graph, doesn't want to have a individual graph for each entity/LDEV value ( will be difficult to compare). For Example : I wanted to create a graph with multiple line plot for LDEV_NUMBER - 00:42:26 , with X-axis value as Record time and Y- Axis value as "READ_IO_COUNT", Similarly, next line graph will represent next LDEV and so on. import io import pandas as pd from pathlib import Path import matplotlib.pyplot as plt data = b'RECORD_TIME,LDEV_NUMBER,READ_IO_COUNT,WRITE_IO_COUNT,READ_MBYTES,WRITE_MBYTES,READ_RESPONSE_RATE,WRITE_RESPONSE_RATE,TOTAL_RESPONSE_RATE\r\ntime_t,string(16),ulong,ulong,ulong,ulong,float,float,float\r\n2020-03-16 00:00:42,"00:42:26",217,0,1,0,9.200517E+01,0.000000E+00,9.200517E+01\r\n2020-03-16 00:01:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:02:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:03:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:04:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:05:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:06:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:07:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:08:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:09:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:10:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:11:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:12:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:13:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:14:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:15:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:16:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:17:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:18:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:19:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:20:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:21:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:22:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:23:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:24:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:25:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:26:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:27:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:28:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:29:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:30:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:31:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:32:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:33:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:34:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:35:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:36:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:37:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:38:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:39:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:40:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:41:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:42:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:43:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:44:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:45:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:46:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:47:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:48:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:49:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:50:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:51:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:52:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:53:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:54:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:55:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:56:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:57:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:58:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:59:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:00:33,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:01:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:02:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:03:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:04:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:05:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:06:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:07:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:08:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:09:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:10:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:11:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:12:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:13:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:14:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:15:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:16:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:17:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:18:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:19:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:20:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:21:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:22:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:23:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:24:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:25:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:26:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:27:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:28:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:29:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:30:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:31:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:32:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:33:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:34:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:35:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:36:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:37:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:38:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:39:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:40:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:41:02,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:42:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:43:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:44:01,"00:42:26",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:55:02,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:56:02,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:57:01,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:58:01,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:59:02,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 02:00:33,"00:42:28",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:17:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:18:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:19:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:20:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:21:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:22:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:23:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:24:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:25:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:26:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:27:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:28:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:29:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:30:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:31:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:32:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:33:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:34:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:35:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:36:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:37:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:38:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:39:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:40:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:41:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:42:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:43:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:44:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:45:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:46:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:47:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:48:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:49:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:50:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:51:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:52:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:53:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:54:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:55:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:56:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:57:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:58:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 00:59:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:00:33,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:01:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:02:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:03:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:04:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:05:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:06:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:07:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:08:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:09:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:10:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:11:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:12:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:13:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:14:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:15:01,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:16:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:17:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:18:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 01:59:02,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n2020-03-16 02:00:33,"00:42:2B",0,0,0,0,0.000000E+00,0.000000E+00,0.000000E+00\r\n\r\n' df = pd.read_csv(io.StringIO(data.decode('ascii'))) df1=df.drop(df.index[0]) Lun_name=["00:42:2A","00:42:2B","00:42:27","00:42:26","00:42:28","00:42:29"] for i in range(len(Lun_name)): plt.plot(df.loc[df['LDEV_NUMBER'] =='%s'%Lun_name[i]]['RECORD_TIME'], df.loc[df['LDEV_NUMBER'] == '%s'%Lun_name[i]]['READ_IO_COUNT']) plt.show() Axes values are disoriented when i try to plot this using above code. [READ IOPS]
with help of my colleague , i resolved it.Issue here is Y- Axis plotting data value are (for Ex: TOTAL_MBYTES ) with datatype as object , after converting it to integer, the axes looks fine . We did a slight modifications to the code as below for i in range(len(portname)): # plt.plot(df.loc[df['LDEV_NUMBER'] =='%s'%Lun_name[i]]['RECORD_TIME'], df.loc[df['LDEV_NUMBER'] == '%s'%Lun_name[i]]['READ_IO_COUNT']) X = list(df1.loc[df1['PORT_NAME'] == '%s' % portname[i]]['DATETIME']) Y = list(df1.loc[df1['PORT_NAME'] == '%s' % portname[i]]['TOTAL_MBYTES']) ax = plt.axes() ax.xaxis.set_minor_locator(dates.HourLocator(interval=4)) # every 4 hours ax.xaxis.set_minor_formatter(dates.DateFormatter('%H:%M')) # hours and minutes ax.xaxis.set_major_locator(dates.DayLocator(interval=1)) # every day ax.xaxis.set_major_formatter(dates.DateFormatter('\n%d-%m-%Y')) for i in range(len(Y)): Y[i] = int(Y[i]) plt.plot(X, Y) plt.ylabel('Processor throughput') plt.xlabel('Time') plt.legend(portname) plt.savefig('port_throughput.png')
How to do a second interpolation in python
I did my first interpolation with numpy.polyfit() and numpy.polyval() for 50 longitude values for a full satellite orbit. Now, I just want to look at a window of 0-4.5 degrees longitude and do a second interpolation so that I have 6,000 points for longitude in the window. I need to use the equation/curve from the first interpolation to create the second one because there is only one point in the window range. I'm not sure how to do the second interpolation. Inputs: lon = [-109.73105744378498, -104.28690174554579, -99.2435132929552, -94.48533149079628, -89.91054414962821, -85.42671400689177, -80.94616150449806, -76.38135021210172, -71.6402674905218, -66.62178379632216, -61.21120467960157, -55.27684029674759, -48.66970878028004, -41.23083703244677, -32.813881865289346, -23.332386757370532, -12.832819226213942, -1.5659455609661785, 10.008077792630402, 21.33116444634303, 31.92601575632583, 41.51883213364072, 50.04498630545507, 57.58103957109249, 64.26993028992476, 70.2708323505337, 75.73441871754586, 80.7944079829813, 85.56734813043659, 90.1558676264546, 94.65309120129724, 99.14730128118617, 103.72658922048785, 108.48349841714494, 113.51966824008079, 118.95024882101737, 124.9072309203375, 131.5395221402974, 139.00523971191907, 147.44847902856114, 156.95146022590976, 167.46163867248032, 178.72228750873975, -169.72898181991064, -158.44642409799974, -147.8993300787564, -138.35373014113995, -129.86955508919888, -122.36868103811106, -115.70852432245486] myOrbitJ2000Time = [ 20027712., 20027713., 20027714., 20027715., 20027716., 20027717., 20027718., 20027719., 20027720., 20027721., 20027722., 20027723., 20027724., 20027725., 20027726., 20027727., 20027728., 20027729., 20027730., 20027731., 20027732., 20027733., 20027734., 20027735., 20027736., 20027737., 20027738., 20027739., 20027740., 20027741., 20027742., 20027743., 20027744., 20027745., 20027746., 20027747., 20027748., 20027749., 20027750., 20027751., 20027752., 20027753., 20027754., 20027755., 20027756., 20027757., 20027758., 20027759., 20027760., 20027761.] Code: deg = 30 #polynomial degree for fit fittime = myOrbitJ2000Time - myOrbitJ2000Time[0] 'Longitude Interpolation' fitLon = np.polyfit(fittime, lon, deg) #gets fit coefficients polyval_lon = np.polyval(fitLon,fittime) #interp.s to get actual values 'Get Longitude values for a window of 0-4.5 deg Longitude' lonwindow =[] for i in range(len(polyval_lon)): if 0 < polyval_lon[i] < 4.5: # get lon vals in window lonwindow.append(polyval_lon[i]) #append lon vals lonwindow = np.array(lonwindow)
First, generate the polynomial fit coefficients using the old time (x-axis) values, and interpolated longitude (y-axis) values. import numpy as np import matplotlib.pyplot as plt poly_deg = 3 #degree of the polynomial fit polynomial_fit_coeff = np.polyfit(original_times, interp_lon, poly_deg) Next, use np.linspace() to generate arbitrary time values based on the number of desire points in the window. start = 0 stop = 4 num_points = 6000 arbitrary_time = np.linspace(start, stop, num_points) Finally, use the fit coefficients and the arbitrary time to get the actual interpolated longitude (y-axis) values and plot. lon_intrp_2 = np.polyval(polynomial_fit_coeff, arbitrary_time) plt.plot(arbitrary_time, lon_intrp_2, 'r') #interpolated window as a red curve plt.plot(myOrbitJ2000Time, lon, '.') #original data plotted as points
Adding a single label to the legend for a series of different data points plotted inside a designated bin in Python using matplotlib.pyplot.plot()
I have a script for plotting astronomical data of redmapping clusters using a csv file. I could get the data points in it and want to plot them using different colors depending on their redshift values: I am binning the dataset into 3 bins (0.1-0.2, 0.2-0.25, 0.25,0.31) based on the redshift. The problem arises with my code after I distinguish to what bin the datapoint belongs: I want to have 3 labels in the legend corresponding to red, green and blue data points, but this is not happening and I don't know why. I am using plot() instead of scatter() as I also had to do the best fit from the data in the same figure. So everything needs to be in 1 figure. import numpy as np import matplotlib.pyplot as py import csv z = open("Sheet4CSV.csv","rU") data = csv.reader(z) x = [] y = [] ylow = [] yupp = [] xlow = [] xupp = [] redshift = [] for r in data: x.append(float(r[2])) y.append(float(r[5])) xlow.append(float(r[3])) xupp.append(float(r[4])) ylow.append(float(r[6])) yupp.append(float(r[7])) redshift.append(float(r[1])) from operator import sub xerr_l = map(sub,x,xlow) xerr_u = map(sub,xupp,x) yerr_l = map(sub,y,ylow) yerr_u = map(sub,yupp,y) py.xlabel("$Original\ Tx\ XCS\ pipeline\ Tx\ keV$") py.ylabel("$Iterative\ Tx\ pipeline\ keV$") py.xlim(0,12) py.ylim(0,12) py.title("Redmapper Clusters comparison of Tx pipelines") ax1 = py.subplot(111) ##Problem starts here after the previous line## for p in redshift: for i in xrange(84): p=redshift[i] if 0.1<=p<0.2: ax1.plot(x[i],y[i],color="b", marker='.', linestyle = " ")#, label = "$z < 0.2$") exit if 0.2<=p<0.25: ax1.plot(x[i],y[i],color="g", marker='.', linestyle = " ")#, label="$0.2 \leq z < 0.25$") exit if 0.25<=p<=0.3: ax1.plot(x[i],y[i],color="r", marker='.', linestyle = " ")#, label="$z \geq 0.25$") exit ##There seems nothing wrong after this point## py.errorbar(x,y,yerr=[yerr_l,yerr_u],xerr=[xerr_l,xerr_u], fmt= " ",ecolor='magenta', label="Error bars") cof = np.polyfit(x,y,1) p = np.poly1d(cof) l = np.linspace(0,12,100) py.plot(l,p(l),"black",label="Best fit") py.plot([0,15],[0,15],"black", linestyle="dotted", linewidth=2.0, label="line $y=x$") py.grid() box = ax1.get_position() ax1.set_position([box.x1,box.y1,box.width, box.height]) py.legend(loc='center left',bbox_to_anchor=(1,0.5)) py.show() In the 1st 'for' loop, I have indexed every value 'p' in the list 'redshift' so that bins can be created using 'if' statement. But if I add the labels that are hashed out against each py.plot() inside the 'if' statements, each data point 'i' that gets plotted in the figure as an intersection of (x[i],y[i]) takes the label and my entire legend attains in total 87 labels (including the 3 mentioned in the code at other places)!!!!!! I essentially need 1 label for each bin... Please tell me what needs to done after the bins are created and py.plot() commands used...Thanks in advance :-) Sorry I cannot post my image here due to low reputation! The data 'appended' for x, y and redshift lists from the csv file are as follows: x=[5.031,10.599,10.589,8.548,9.089,8.675,3.588,1.244,3.023,8.632,8.953,7.603,7.513,2.917,7.344,7.106,3.889,7.287,3.367,6.839,2.801,2.316,1.328,6.31,6.19,6.329,6.025,5.629,6.123,5.892,5.438,4.398,4.542,4.624,4.501,4.504,5.033,5.068,4.197,2.854,4.784,2.158,4.054,3.124,3.961,4.42,3.853,3.658,1.858,4.537,2.072,3.573,3.041,5.837,3.652,3.209,2.742,2.732,1.312,3.635,2.69,3.32,2.488,2.996,2.269,1.701,3.935,2.015,0.798,2.212,1.672,1.925,3.21,1.979,1.794,2.624,2.027,3.66,1.073,1.007,1.57,0.854,0.619,0.547] y=[5.255,10.897,11.045,9.125,9.387,17.719,4.025,1.389,4.152,8.703,9.051,8.02,7.774,3.139,7.543,7.224,4.155,7.416,3.905,6.868,2.909,2.658,1.651,6.454,6.252,6.541,6.152,5.647,6.285,6.079,5.489,4.541,4.634,8.851,4.554,4.555,5.559,5.144,5.311,5.839,5.364,3.18,4.352,3.379,4.059,4.575,3.914,5.736,2.304,4.68,3.187,3.756,3.419,9.118,4.595,3.346,3.603,6.313,1.816,4.34,2.732,4.978,2.719,3.761,2.623,2.1,4.956,2.316,4.231,2.831,1.954,2.248,6.573,2.276,2.627,3.85,3.545,25.405,3.996,1.347,1.679,1.435,0.759,0.677] redshift = [0.12,0.25,0.23,0.23,0.27,0.26,0.12,0.27,0.17,0.18,0.17,0.3,0.23,0.1,0.23,0.29,0.29,0.12,0.13,0.26,0.11,0.24,0.13,0.21,0.17,0.2,0.3,0.29,0.23,0.27,0.25,0.21,0.11,0.15,0.1,0.26,0.23,0.12,0.23,0.26,0.2,0.17,0.22,0.26,0.25,0.12,0.19,0.24,0.18,0.15,0.27,0.14,0.14,0.29,0.29,0.26,0.15,0.29,0.24,0.24,0.23,0.26,0.29,0.22,0.13,0.18,0.24,0.14,0.24,0.24,0.17,0.26,0.29,0.11,0.14,0.26,0.28,0.26,0.28,0.27,0.23,0.26,0.23,0.19]
Working with numerical data like this, you should really consider using a numerical library, like numpy. The problem in your code arises from processing each record (a coordinate (x,y) and the corresponding value redshift) one at a time. You are calling plot for each point, thereby creating legends for each of those 84 datapoints. You should consider your "bins" as groups of data that belong to the same dataset and process them as such. You could use "logical masks" to distinguish between your "bins", as shown below. It's also not clear why you call exit after each plotting action. import numpy as np import matplotlib.pyplot as plt x = np.array([5.031,10.599,10.589,8.548,9.089,8.675,3.588,1.244,3.023,8.632,8.953,7.603,7.513,2.917,7.344,7.106,3.889,7.287,3.367,6.839,2.801,2.316,1.328,6.31,6.19,6.329,6.025,5.629,6.123,5.892,5.438,4.398,4.542,4.624,4.501,4.504,5.033,5.068,4.197,2.854,4.784,2.158,4.054,3.124,3.961,4.42,3.853,3.658,1.858,4.537,2.072,3.573,3.041,5.837,3.652,3.209,2.742,2.732,1.312,3.635,2.69,3.32,2.488,2.996,2.269,1.701,3.935,2.015,0.798,2.212,1.672,1.925,3.21,1.979,1.794,2.624,2.027,3.66,1.073,1.007,1.57,0.854,0.619,0.547]) y = np.array([5.255,10.897,11.045,9.125,9.387,17.719,4.025,1.389,4.152,8.703,9.051,8.02,7.774,3.139,7.543,7.224,4.155,7.416,3.905,6.868,2.909,2.658,1.651,6.454,6.252,6.541,6.152,5.647,6.285,6.079,5.489,4.541,4.634,8.851,4.554,4.555,5.559,5.144,5.311,5.839,5.364,3.18,4.352,3.379,4.059,4.575,3.914,5.736,2.304,4.68,3.187,3.756,3.419,9.118,4.595,3.346,3.603,6.313,1.816,4.34,2.732,4.978,2.719,3.761,2.623,2.1,4.956,2.316,4.231,2.831,1.954,2.248,6.573,2.276,2.627,3.85,3.545,25.405,3.996,1.347,1.679,1.435,0.759,0.677]) redshift = np.array([0.12,0.25,0.23,0.23,0.27,0.26,0.12,0.27,0.17,0.18,0.17,0.3,0.23,0.1,0.23,0.29,0.29,0.12,0.13,0.26,0.11,0.24,0.13,0.21,0.17,0.2,0.3,0.29,0.23,0.27,0.25,0.21,0.11,0.15,0.1,0.26,0.23,0.12,0.23,0.26,0.2,0.17,0.22,0.26,0.25,0.12,0.19,0.24,0.18,0.15,0.27,0.14,0.14,0.29,0.29,0.26,0.15,0.29,0.24,0.24,0.23,0.26,0.29,0.22,0.13,0.18,0.24,0.14,0.24,0.24,0.17,0.26,0.29,0.11,0.14,0.26,0.28,0.26,0.28,0.27,0.23,0.26,0.23,0.19]) bin3 = 0.25 <= redshift bin2 = np.logical_and(0.2 <= redshift, redshift < 0.25) bin1 = np.logical_and(0.1 <= redshift, redshift < 0.2) plt.ion() labels = ("$z < 0.2$", "$0.2 \leq z < 0.25$", "$z \geq 0.25$") colors = ('r', 'g', 'b') for bin, label, co in zip( (bin1, bin2, bin3), labels, colors): plt.plot(x[bin], y[bin], color=co, ls='none', marker='o', label=label) plt.legend() plt.show()