How to reset XTickLabel to default - matlab

In R2010b, I can reset the tick labels to auto thru figure editor,
but I'd like to reset them to default programmatically
I tried
set(gca,'XTickLabel','auto')
But it displays 'auto' at each tick... Any hint ?

You need to set XTickLabelMode to 'auto':
set(gca,'XTickLabelMode','auto')
Tick label modes are set to 'manual' when you specify tick labels. So, you need to turn it back to 'auto'.

OK, I finally found this way:
set(gca,'XTickLabel', num2str(get(gca,'XTick')'));
I read the ticks and transform them back to strings...
EDIT: note that this a workaround that happens to work if you don't zoom nor resize the figure, but which is not robust to zoom/resize because the XTickLabelMode remains 'manual' and thus the XTickLabel won't be updated when you zoom.
I added this answer because this is the first thing I found (and others might find too).
The reason why it is not the preferred way is more usefull than the answer itself, thus this edit.
The right solution to do it, is the one that I accepted.

Related

Plots all red and green

I seem to have made some settings change where all of my MATLAB plots (plot, plot3, surf, etc) show up in this red/green color scale:
I searched around forums and the MATLAB user guide but am not finding anything. It's not a huge deal, as I can enter code to fix this on each plot, but I shouldn't have to.
How to fix this?
Check startup.m you seem to have set your default colormap to autumn or something. Just put it back to either jet (pre 2015a), or parula.
I don't know about the whole settings. These two commands can reset a figure properties (including its colormap) to its default values:
h=gcf;
reset(h)
This way you assign a handle to the last figure you have. Then, the second command resets its options to default values.
Update after Adrian's comment: Check out this page: Default Property Values It clearly shows how is it possible to regenrate the problem you have and you might need use the remove option for removing user-defined default value. There is a factory defined colormap accessible by the function: get(groot,'factoryFigureColormap'). This might help you too.

Bad clarity using export_fig

I am using Export_fig to export figs from matlab, I am getting very good plots generally. But when i add some textboxs and arrows in the fig. the clarity is pathetic.
I use the -transparent property, which does not work either.
export_fig('path', '-pdf','-transparent')
Anyone knows what is happening here. Normally this works very good, only when the text is added it acts like this way. Not sure if it's a glitch in the code or if i am doing anything wrong.
Note: I added the text and arrows with insert option on the menu bar.
If you are not set on using Export_fig for other reasons, consider using MATLAB's built-in print function and increase the resolution with the -r attribute
print('path', '-dpdf', '-r300')
where 'path' is the desired 'path\filename.pdf', '-dpdf' sets the file type, and '-r300' sets the resolution to 300 dpi, also try '-r0' for screen resolution, or higher, till you get what you want.
I'm not sure what the '-transparent' argument is used for but there is probably an equivalent you can find in the documentation.
https://www.mathworks.com/help/matlab/ref/print.html

Pie with legend

I want to add legend to matlab pie instead of just putting the names close the pie itself. That is, I want names to be displayed in a box, and the percentage to be displayed close to the pie (as it usually is). But if I simply add a legend, as follows, it will be not attached to the patches information:
pieH=pie([.3,.4,.3]);
legend({'Leg1','Leg2','Leg3'},'location','EastOutside');
I've tried turning the patch annotation icon display to on, as follows, but it didn't work:
set(get(get(pieH(1),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
set(get(get(pieH(3),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
set(get(get(pieH(5),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
I also tried passing the patched handles, as it says in the help, also with no effect:
legend([pieH(1:2:end)],{'Leg1','Leg2','Leg3'},'location','EastOutside');
Edit
I was using matlab handle graphics version 2, and it seems that this combinations does not work yet at new graphics version. Since it is a matlab bug and this topic led me to the discovering, I am closing it. But if someone, by chance, already had this issue and knows how to workaround please let me know.
here's a way to make it work:
X=[100 200 300];
h=pie(X);
legend(h(1:2:end), 'Small', 'Medium', 'Large','location','EastOutside');

How do I remove these alternating bands on an SSRS chart

Simple question. But I just can't seem to find the answer.
I've tried setting background patterns and styles to none.
It must be me.
I think I've found it.
You click in the Axis Properties and select Axis Options and then remove the check for Use Interlace Colour
et voilĂ !
I'm assuming you're using 2008 since it's not mentioned - let me know if I need to update this.
Right click on the Axis and make sure Show Major Gridlines is unchecked:
Edit after comment:
Another way you can have bands in charts is through Striplines. Do you have anything set up under this property for your Axis?
Remove any that exist in the Collection.

Enableing Line Smoothing causes axes drawing errors

In Matlab 2011a I am plotting a line, and I use the parameter ("LineSmoothing", 1) to make the line look prettier, but it causes the Y and X axis to disappear.
Does someone know what is causing this, and more importantly, how it can be fixed?
I tried the opengl('OpenGLLineSmoothingBug',1) but it didn't change anything.
Thanks in advance!
The undocumented LineSmoothing property causes the figure to automatically switch to using the OpenGL renderer. And the bug you've shown in fact affects all OpenGL-rendererd figures (regardless of this property use).
Example: (tested on R2012a in WinXP)
plot(1:10,'o-'), box on
set(gcf, 'Renderer','opengl')
note how the top and right borders of the box disappear once you execute the second line.
There are some suggested workarounds.