Automatically plot different colored lines

You could use a colormap such as HSV to generate a set of colors. For example: cc=hsv(12); figure; hold on; for i=1:12 plot([0 1],[0 i],’color’,cc(i,:)); end MATLAB has 13 different named colormaps (‘doc colormap’ lists them all). Another option for plotting lines in different colors is to use the LineStyleOrder property; see Defining the Color … Read more

Line break in expression()?

You can easily use line breaks in regular paste, but this is plotmath paste (actually a different function also with no ‘sep’ argument) and the (long) ?plotmath page specifically tells you it cannot be done. So what’s the work-around? Using the plotmath function atop is one simple option: expression(atop(“Histogram of “*hat(mu), Bootstrap~samples*’,’~Allianz)) This will break … Read more

How can I rotate xticklabels in matplotlib so that the spacing between each xticklabel is equal?

The labels are centered at the tickmark position. Their bounding boxes are unequal in width and might even overlap, which makes them look unequally spaced. Since you’d always want the ticklabels to link to their tickmarks, changing the spacing is not really an option. However you might want to align them such the the upper … Read more

How can I plot data with confidence intervals?

Here is a plotrix solution: set.seed(0815) x <- 1:10 F <- runif(10,1,2) L <- runif(10,0,1) U <- runif(10,2,3) require(plotrix) plotCI(x, F, ui=U, li=L) And here is a ggplot solution: set.seed(0815) df <- data.frame(x =1:10, F =runif(10,1,2), L =runif(10,0,1), U =runif(10,2,3)) require(ggplot2) ggplot(df, aes(x = x, y = F)) + geom_point(size = 4) + geom_errorbar(aes(ymax = … Read more

Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python

plt.subplots() is a function that returns a tuple containing a figure and axes object(s). Thus when using fig, ax = plt.subplots() you unpack this tuple into the variables fig and ax. Having fig is useful if you want to change figure-level attributes or save the figure as an image file later (e.g. with fig.savefig(‘yourfilename.png’)). You … Read more

Plotting bar charts on map using ggplot2?

Update 2016-12-23: The ggsubplot-package is no longer actively maintained and is archived on CRAN: Package ‘ggsubplot’ was removed from the CRAN repository.> Formerly available versions can be obtained from the archive.> Archived on 2016-01-11 as requested by the maintainer garrett@rstudio.com. ggsubplot will not work with R versions >= 3.1.0. Install R 3.0.3 to run the … Read more

How should I update the data of a plot in Matlab?

Short answer : always use Set(‘Xdata’,…’). Example code: function PlotUpdate() x = 0:.1:8; y = sin(x); h = plot(x,y); y = sin(x.^3); set(h,’XData’,x,’YData’,y); end Long answer: There are three relevant measures by which one should choose the best method. Code clarity – How easy it is for someone to read your code? Runtime – How … Read more