Is it possible to create x tick labels with a fixed width

Is it possible to create xticklabels that wraps the text when it gets to long to a new line. I have a program that creates a bar graphs based on existing data. The number of bars on the graph changes anywhere from 1 to 10. On the xticklabels I want to have a description of each bar that goes to a new line as to not interfere with any other text. I am aware of https://www.mathworks.com/matlabcentral/answers/218675-is-it-possible-to-create-textbox-with-fixed-width-on-a-plot this method, but that just creates an annotation not an xticklabel. Is it possible to use 'FitBoxToText' when using xtixklabels. an example set of data I would have would be a 4x3 matrix that contains the quantity, a part number and a description.
An example of the data 2ould look like
Then the output graph would look like

Réponses (1)

dpb
dpb le 15 Jan 2020
Modifié(e) : dpb le 15 Jan 2020
AFAIK, no, that's an amenity TMW hasn't yet provided with the ticklabel property. It's a very simple text string with formatting limited to what can do w/ TeX subset and fonts, etc. It's not a text box control or anything even approaching such.
It undoubtedly can be made to work but you'll have to do the line breaks yourself.
I think using the annotation "trick" with positions centered on the tick values will be your simplest route by far.
You could check File Exchange and see if somebody has already done the heavy lifting for you; if not your function would be a useful submittal.

4 commentaires

There is one on the file exchange called fix_xticklabels by Pekka kumpulainen. It works pretty well but has its limitations as you cannot drag the corner of the text box and resize it like an annotation text box. The other problem I have with it is when I have a lot of bars in a bar graph it tends to out all the xlabels on top of one another
You'll probably either have to "roll your own" or perhaps modify the FEX submisssion.
I would guess you'll need to retrieve the xtick positions to determine the width you want a priori given the variable number of bars will be the primary trick to make it work as desired. Then, you'll have to convert units to points and font size, etc., etc., ...
I was thinking that would have to be done and is doable. But how would you stick the text ticklabels to the graph, so when the graph would move the labels move with it

Connectez-vous pour commenter.

Catégories

Produits

Version

R2015b

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by