Below is a part of my code.
[leg, hobj1] = legend('MFR1', 'MFR2', 'MFR3', 'MFR4', 'MFR5', 'Reference') ;
textobj = findobj(hobj1, 'type', 'text');
set(textobj, 'Interpreter', 'latex', 'fontsize', 12);
legend(leg, "location", "northeast");
The code works perfectly fine. Now I change the last row with location from "northeast" to "northwest":
legend(leg, "location", "northwest");
Problem: Although the legend moves to the location desired, the properties of the legend do not change. i.e., the font size does not change, the text Reference goes outside the box. This happens for all the locations except northeast.
For me, the latex interpreter is not really necessary, I used it to solve my main problem of the legend box either going outside my plot or the text inside the box extending outside the box.
Can someone please help me with this?
Thank you
I tried to reproduce your problem, but for me the "northeast" had the problem with text outside of the legend box. I am not sure, but I think that the fontsize isn't updated in your original northeast location, and updating for the other locations. Either way, the text fit inside the box when I used fontsize 10 instead.
set(textobj, 'Interpreter', 'latex', 'fontsize', 10);
Related
I am having trouble aligning Horizontal Bar graph x-axis Labels, I have long names that I have wrapped using /n. The labels are no longer right aligned (see picture). Is there a way to left or right align (see image)?
I am new creating charts in CF and am stumbling around, if anyone can point me to any documentation that will allow me to know what are valid attributes are for elemets (ie: xAxis...itemsOverlap), I stumbled on this from a post but don't know where to find this info, thanks.
While I am here is there any way to change the color of the value displayed for each bar? (or have that number appear inside the bar?).
again thank for your patients as I am new to this.
<CFSET xAxis_disp = {"itemsOverlap":true, "max-items": SQL_Query.RecordCount}>
<CFSET aspect3d_small={"angle":0,"depth":7,"true3d":false}>`
<CFSET yAxisStep_25 = {"min-value":"0","step":"5"}>
<CFCHART
style="default"
show3d="yes"
chartHeight="#chartHeight_error#"
chartwidth="500"
type="horizontalbar"
gridlines="20"
yAxis = "#yAxisStep_25#"
xAxis="#xAxis_disp#"
aspect3d="#aspect3d_small#"
font="times" >
<CFCHARTSERIES
colorlist="##234086,##284A99,##284A99,##325CC0,##3D68CD,##5077D2,##6486D7,##7795DC,##8BA4E1"
query="SQL_Query"
type="bar"
datalabelstyle="value"
itemcolumn="CRFNAME"
valuecolumn="ErrCounter">
</CFCHARTSERIES>
</CFCHART>
Chart Labels, not aligned
FWIW, CFChart is just a wrapper around ZingChart, so the ZingCharts docs will be more helpful for stuff like this. I usually end up googling "How to do [X] with ZingChart" and/or pore over the ZingChart docs to find the syntax ... then figure out how it maps to the CF attributes with a little trial and error :-).
Anyway, the xAxis item alignment is controlled with "item": { "text-align":"right"}. Add it to your xAxis_disp structure. For the other xAxis attributes (i.e. "Scale-X"), have a look at the ZingChart docs
<CFSET xAxis_disp = {"items-overlap":true
, "max-items": 6
, "auto-fit": true
, "item": { "text-align":"right"}
}>
Runnable TryCF.com Example
This is a new question related to a previous question I asked:
holoviews can't find flexx when using a Dimension value_format callback
Thanks to downgrading my version of flexx, I am no longer getting the warning message. However, the callback function is not working. Here is the code:
%%output size=200
%%opts Curve [width=600 height=250] {+framewise}
%%opts Curve.Load.Ticket (color='red')
def xformat(x):
# update the default tick label to append an 'a'
new = x + 'a'
return(new)
kdims=hv.Dimension('Day Section', label='Week Day and Hour', value_format=xformat)
tload = hv.Curve(simple_pd,vdims=[('Max Ticket Load', 'Maxiumum Ticket Load')],kdims=kdims,group='Load',label='Ticket')
tload
When I run with the above code, I expect to see the same amount of x axis tick labels, however, each label should have an 'a' appended to the end. However, what I am seeing is no rendering of the element at all in my notebook. I have tried a number of variations of modifying the value, and the same thing happens.
Strangely, the issue appears to be the use of the variable name new in the xformat function. If I change the name of the variable it works fine. It doesn't appear as though new is a reserved work in python though, so I am not sure why its causing a problem.
Note that using the matplotlib extension does not have the same problem, only Bokeh.
So when trying to add a HoverTool to a plot, the MultiLine Hover works.
But the problem I am having is, that I have another highlighting Single Line, that I do not want the Hover to act on.
So I wanted to input just the multiline to the renderers keyword
p.add_tools(HoverTool(tooltips = [('Name: ', '#Name'),
('Value', '#Value')],
renderers = [multiline]
)
and I am getting the following error:
ValueError: expected an element of either Auto or List(Instance(Renderer)), got [MultiLine(id='4982e76f-7dda-4d78-b729-240c9a29bdef', ...)]
What am I missing?
Glyphs (such as MultiLine) are more like a description of what to draw. There is a seperate GlyphRenderer that takes glyphs and uses them to draw (it can actually have several versions of a glyph to use in different cases, e.g. for selecting and highlighting and decimating). The renderers arg of the hover tool expects the GlyphRenderer, not the glyph.
If you are using bokeh.plotting, then the glyph renderer is returned by the method on the figure:
r = plot.multi_line(...) # r is what to configure on the hover tool
If you are using the low level bokeh.models API then you must already be configuring a GlyphRenderer manually for your MultiLine. Pass that to the hover tool instead.
My aim is to create a text image and put it on top of other images. This is the command I use to create the text image:
String[] cp_img_arguments = {"convert",
"-size", width_size + "x",
"-background", background_colour,
"-pointsize", pointsize.toString(),
"-font", font_path,
"-fill",text_colour,
"caption:" + text,
destination};
In order to calculate the size of the image I need, I make use of FontsMetrics like this:
Font font = new Font(fontName, Font.PLAIN, pointsize);
Canvas canvas = new Canvas();
fontMetrics = canvas.getFontMetrics(font);
width_size = fontMetrics.stringWidth(toString());
Although I often generate images with the text truncated or multi-line, which means the width I calculate is not actually enough for the text.
The font comes from a .ttf file. I believe this miss-calculation happens because of the density/DPI parameter in GraphicsMagick. I am not currently using it (default is 55 I believe), but I wonder how that affects the actual font size, compared to what FontMetrics calculate.
Does anyone have experience generating images with text using gm? Any ideas how I can make the image dimension calculation more accurate?
I've got a really simple application for adding watermarks to pictures. So you can drop your pictures in a QListWidget which shows you a thumbnail and the path, adjust some things like the text, the transparency, the output format and so on.. and after pressing start it saves the copyrighted picture in a destination of your choice. This works with a QPainter which paints the logo and text on the picture.
Everything is able to work fine. But here's the misterious bug:
The application kills random letters. It's really strange, because I can't reproduce it. With every execution and combination of options it's different. For example:
Sometimes I can't write some letters in the QLineEdit of my interface (like E, 4 and 0 doesnt exist, or he changes the letters so some special signs).
The text of the items in the QListWidget aren't completly displayed, sometimes completley missing. But I can extract the text normally and use the path.
While execution I have a QTextBrowser as a log to display some interesting things like the font size. Although, the font is shown normaly on the resulting picture, it says " 4" or "6" instead of much higher and correct sizes. Betimes strange white blocks appear between some letters
When drawing text on the picture with a QPainter, there also letters missing. Sometimes, all the letters are printed over each other. It seems like this bug appears more often when using small pixelsizes (like 12):
//Text//
int fontSize = (watermarkHeight-(4*frame));
int fontX = 2*frame;
int fontY = (result.height()-(watermarkHeight-2*frame));
int fontWidth = watermarkWidth;
QRect place(fontX,fontY,fontWidth,fontSize);
QFont font("Helvetica Neue", QFont::Light);
font.setPixelSize(fontSize);
emit log(QString::number(fontSize));
pixPaint.setFont(font);
pixPaint.setPen(QColor(255,255,255,textOpacity));
pixPaint.drawText(place,text);
Not all of these bugs appear at once! Sometimes I haven't got any bugs...
Perhaps someone had a similar bug before. Unfortunately I didn't found something like this in the internet. I didn't post a lot of code snippets because I think (and hope) that this is a gerneral problem. If you need something specific to help me, please let me know =)
I've added a example picture:
In the lineEdit I simply wrote ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 (look what he has done with the 7 and 9)
This small square in the lower corner of the picture should be the "ABC..." thing
The "62" looks very strange in the textBrowser
I'm using Qt 5.0.1 on a Windows 7 64Bit computer.
EDIT: Everytime after adding the first picture to the list, he's finding these warnings:
QFontEngine::loadEngine: GetTextMetrics failed ()
QWindowsFontEngine: GetTextMetrics failed ()
But when I change the height (and with it the pointSize of the font) its not emitted anymore, even with the start-parameters.
EDIT 2: Thank you for your help! I corrected my code so that he only uses correct fonts and correct sizes, but it still doesn't work. When I remove the QPainter::drawText() function it works fine (without the text). But as soon as I am adding text everything is bugged. I have something like this now:
//Text//
QList<int> smoothSizes = fontDatabase->smoothSizes("Verdana","Standard");
int fontSize = (watermarkHeight-(4*frame))*0.75;
emit log("Requested: "+QString::number(fontSize));
if(!smoothSizes.contains(fontSize)){
for(int i = 0; i<smoothSizes.length(); i++){
if(smoothSizes.at(i) > fontSize && i>0){
fontSize = smoothSizes.at(i-1);
break;
}
}
}
int fontX = 2*frame;
int fontY = (result.height()-(watermarkHeight/2)+frame);
QFont font = fontDatabase->font("Verdana","Standard",fontSize);
QFontInfo info(font);
emit log("Corrected: "+QString::number(fontSize));
emit log("Okay?: "+QString::number(info.exactMatch()));
pixPaint.setFont(font);
const QFontMetrics fontMetrics = pixPaint.fontMetrics();
if(info.exactMatch()){
pixPaint.setPen(QColor(255,255,255,textOpacity));
pixPaint.drawText(fontX,fontY+(fontMetrics.height()-fontMetrics.ascent()),text);
}
It almost sounds like you are corrupting random memory in your process, or you have a badly broken Windows install. Possibly your font request is matched by a very poorly chosen system font.
Whatever is set on a QFont is merely a request. To obtain the parameters of the actual font that was selected, you must create a QFontInfo, and get your information from there.
Imagine that you request a QFont that doesn't exist on a system, or that can't be scaled to a particular size. At some point the font object would need to morph to reflect what really happened - this would be very confusing. Thus, the QFontInfo provides the information about the font that was actually used. Think of QFontInfo as a response, and QFont as a request.
I finally found a solution: I simply updated Qt from 5.0.1 to 5.2.1, now it works. Perhaps someone has a similar bug and this post helps him. Thank you for your help!