showing all Y axis in bar chart - MSChart - mschart

How can I show all text values of Y axis in the bar chart shown in the image

Chart1.ChartAreas[0].AxisX.Interval = 1;

Related

Sort the detected text bounding box coordinates on basis of order of appearance in image

I have used a text detection model which gives the bounding box coordinates . I have converted the polygons to rectangles for cropping the text area in the image. The resulted bounding boxes are shuffled and i could not sort it out. As per my understanding, the boxes are sorted on the basis of Y3. But when there is a presence of curved text in a same line like in the image below, the order gets shuffled and i need to sort it before passing it to text extraction model.
Image with polygon coordinates
Converted the polygons to rectangles for cropping text areas
same image with converted rectangle bounding box
img_name='rre7'
orig=cv2.imread('CRAFT-pytorch/test/'+str(img_name)+'.jpg')
colnames=['x1','y1','x2','y2','x3','y3','x4','y4']
df=pd.read_csv('result/res_'+str(img_name)+'.txt',header=None,
delimiter=',', names=colnames)
rect=[]
boxes=df.values
for i,(x1,y1,x2,y2,x3,y3,x4,y4) in enumerate(boxes):
startX = min([x1,x2,x3,x4])
startY = min([y1,y2,y3,y4])
endX = max([x1,x2,x3,x4])
endY = max([y1,y2,y3,y4])
#print([startX,startY,endX,endY])
rect.append([startX,startY,endX,endY])
rect.sort(key=lambda b: b[1])
print("After sorting")
print('\n')
# initially the line bottom is set to be the bottom of the first rect
line_bottom = rect[0][1]+rect[0][3]-1
line_begin_idx = 0
for i in range(len(rect)):
# when a new box's top is below current line's bottom
# it's a new line
if rect[i][1] > line_bottom:
# sort the previous line by their x
rect[line_begin_idx:i] = sorted(rect[line_begin_idx:i], key=lambda
b: b[0])
line_begin_idx = i
# regardless if it's a new line or not
# always update the line bottom
line_bottom = max(rect[i][1]+rect[i][3]-1, line_bottom)
# sort the last line
rect[line_begin_idx:] = sorted(rect[line_begin_idx:], key=lambda b: b[0])
for i,(startX,startY, endX,endY) in enumerate(rect):
roi = orig[startY:endY, startX:endX]
cv2.imwrite('gray/'+str(img_name)+'_'+str(i+1)+'.jpg',roi)
In this case the polygon bounding box coordinates with detected text are
146,36,354,34,354,82,146,84 "Australian"
273,78,434,151,411,201,250,129 "Collection"
146,97,250,97,250,150,146,150 "vine"
77,166,131,126,154,158,99,197 "Old"
242,215,361,241,354,273,235,248 "Valley"
140,247,224,219,234,250,150,277 "Eden"
194,298,306,296,307,324,194,325 "Shiraz"
232,406,363,402,364,421,233,426 "Vintage"
152,402,216,405,215,425,151,422 "2008"
124,470,209,480,207,500,122,490 "South"
227,481,387,472,389,494,228,503 "Australia"
222,562,312,564,311,585,222,583 "Gibson"
198,564,217,564,217,584,198,584 "by"
386,570,421,570,421,600,386,600 "750 ml"
But the expected output is that i need the coordinates sorted in the following order of text appearance....Australian->old->vine->collection->Eden->Valley->shiraz->2008->vintage->south->Australia->by->GIBSON->750ml.

the result of density contour plot with histogram2d and matplotlib

i am trying to plot a 2D contour density map using histogram2d, i2d turned the histogram output into contour plot and plotted my data with contourf but i didn't appreciated the result, since it gives me a map with a huge rectangle in the middle.
here's the code i'm usingenter image description here
db = 1
lon_bins = np.linspace(min(lons)-db, max(lons)+db, (max(lons)-min(lons))*100)
lat_bins = np.linspace(min(lats)-db, max(lats)+db, (max(lats)-min(lats))*100)
h, xedges, yedges = (np.histogram2d(lats, lons,[lat_bins, lon_bins])
yi, xi = m(*np.meshgrid(lon_bins, lat_bins))
g = np.zeros(xi.shape)
g[:-1,:-1] = h
g[-1] = g[0] # copy the top row to the bottom
g[:,-1] = g[:,0] # copy the left column to the right
print g.shape,yi.shape,xi.shape
cs = m.contourf(yi, xi, g, cmap='Dark2')
cbar = plt.colorbar(cs, orientation='horizontal')
cbar.set_label('la densite des impacts foudre',size=18)
plt.gcf().set_size_inches(15,15)
plt.show()
And here's the result i got
so my request is how to have a nicer plotting, i don't want to have that rectangle in the middle ,i want my result being more smoothed...any ideas ?
I found the answer of my request,so in order to get rid of that rectangle i added this to my code :
g[g==0.0] = np.nan
which means, the bins that have density equal to 0 wouldn't appear on the plot and it's working fine.

How to set a fixed range to the KDChart BarDiagram?

I want to display a BarDiagram using the KDChart library. The vertical values shall be between -120 to 0.
Normally, KDChart starts the bars at 0 as the follow png shows:
Bar Diagram with 0 on top and -120 at the bottom, with the bars growing from 0 towards -120 http://bvdpi.img36.wal8.com/img36/371522_20130905114637/137835282162.png
Now KDChart::CartesianCoordinatePlane has a method setVerticalRangeReversed(bool).
After calling the method, the diagram looks like this:
Bar Diagram with -120 on top and 0 at the bottom, with the bars growing from 0 towards -120 http://bvdpi.img36.wal8.com/img36/371522_20130905114637/137835282217.png
What I need is a mix of both, where the bars are like in the bottom picture, but the Y Axis is like in the upper picture.
Is there any way in KDChart to let the bars start at -120 and grow towards 0?
Because the y axis values has min value -120, I convert the values from [-120,0] to [0, 120],
by each value plus abs(-120).
value += abs(-120);
Also we must convert the y axis ticks, CartesianAxis has a interface setAnnotations(QMap). So I made a map like this:
QMap<double, QString> m;
m.insert(0, "-120");
m.insert(20, "-100");
m.insert(60, "-60");
//...
m.insert(120, "0");
yAxis->setAnnotations(m);
Now, the chart looks normally:
You can set the range of the axis manually using:
CartesianCoordinatePlane::setVerticalRange(const QPair< qreal, qreal > & range)
So your code would look like this:
static_cast<CartesianCoordinatePlane*>(chart->coordinatePlane())->setVerticalRange(qMakePair(-120,0));

plot data points in python using pylab

I have data which I have to plot
X = [0,1,2,3,4,5]
Y = [6,7,8,9,10,11,12,13,14,15]
X belongs to class1, so I would want them to be plotted green in color and Y belongs to class2, so I would want them to be plotted blue in color.
What I did was,
import pylab as pl
pl.plot(X,'go')
pl.plot(Y,'bo')
pl.show()
But this is plotting X against Y. All I want to display in my graph is just the points X and Y in green and blue colors respectively.
How can I accomplish this?
It doesn't plot X against Y, if only because X and Y are not the same length. Let's say x is the variable (horizontal axis) and y the result (vertical axis). Normally you write pl.plot(x,y), where x and y are lists of the same length. If you give only one list, it assumes you only gave y and matplotlib will make an x-axis for you, something like this:
import pylab as pl
y1 = [0,1,2,3,4,5]
y2 = [6,7,8,9,10,11,12,13,14,15]
x1 = range(len(y1))
x2 = range(len(y2))
pl.plot(x1, y1,'go')
pl.plot(x2, y2,'bo')
pl.show()
So I think in your case you should define the x-axis.

Google chart image, add labels to the X and Y axis

I am using:
http://code.google.com/apis/chart/image/
I want to describe that the X is "Meal number" and Y is "calories"
chs=440x220
chxt=y,x
cht=lc
chco=3072F3
chd=t:931.4,23.5,572.4,0,0,0,0
chds=0,2500
chxr=0,0,2500|1,1,7,1
chdl=Energi
chdlp=b
chls=2
chma=5,5,5,25
chm=o,000000,0,-1,5
You can try and see here:
http://code.google.com/apis/chart/image/docs/chart_playground.html
I already have labels for X and Y. The X axis 1,2,3,4... and the Y axis 0,250,500...
I want to add at the top or bottom on the Y axis: Calories
And on the X axis: Meal number
I found this:
http://www.lornajane.net/posts/2011/adding-multiple-axis-labels-to-a-google-chart
But i dont know how to do it on a Line chart
The chxl parameter allows you to specify the label and chxp enables you to position the labels, e.g.:
http://chart.apis.google.com/chart
?chxl=0:|Calories||1:|Hours
&chxp=0,100|1,50
&chxt=y,x
&chbh=a
&chs=300x225
&cht=bvg
&chco=A2C180,3D7930
&chd=t:10,50,60,80,40,60,30|50,60,100,40,20,40,30
&chtt=Vertical+bar+chart
More detail (including how to apply styles to axis labels):
http://code.google.com/apis/chart/image/docs/gallery/bar_charts.html#axis_labels