Minimizing NExpectation for a custom distribution in Mathematica

This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution following along the lines discussed by @Sasha in a number of answers over the past year. Code defining the distributions follows: nDist /: CharacteristicFunction[nDist[a_, b_, … Read more

Is there a way to detach matplotlib plots so that the computation can continue?

After these instructions in the Python interpreter one gets a window with a plot: from matplotlib.pyplot import * plot([1,2,3]) show() # other code Unfortunately, I don’t know how to continue to interactively explore the figure created by show() while the program does further calculations. Is it possible at all? Sometimes calculations are long and it … Read more

Plot two histograms on single chart with matplotlib

I created a histogram plot using data from a file and no problem. Now I wanted to superpose data from another file in the same histogram, so I do something like this n,bins,patchs = ax.hist(mydata1,100) n,bins,patchs = ax.hist(mydata2,100) but the problem is that for each interval, only the bar with the highest value appears, and … Read more

How to add title to subplots in Matplotlib

I have one figure which contains many subplots. fig = plt.figure(num=None, figsize=(26, 12), dpi=80, facecolor=”w”, edgecolor=”k”) fig.canvas.set_window_title(‘Window Title’) # Returns the Axes instance ax = fig.add_subplot(311) ax2 = fig.add_subplot(312) ax3 = fig.add_subplot(313) How do I add titles to the subplots? fig.suptitle adds a title to all graphs and although ax.set_title() exists, the latter does not … Read more

Adding a legend to PyPlot in Matplotlib in the simplest manner possible

TL;DR -> How can one create a legend for a line graph in Matplotlib‘s PyPlot without creating any extra variables? Please consider the graphing script below: if __name__ == ‘__main__’: PyPlot.plot(total_lengths, sort_times_bubble, ‘b-‘, total_lengths, sort_times_ins, ‘r-‘, total_lengths, sort_times_merge_r, ‘g+’, total_lengths, sort_times_merge_i, ‘p-‘, ) PyPlot.title(“Combined Statistics”) PyPlot.xlabel(“Length of list (number)”) PyPlot.ylabel(“Time taken (seconds)”) PyPlot.show() As you … Read more

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

I’m learning to use matplotlib by studying examples, and a lot of examples seem to include a line like the following before creating a single plot… fig, ax = plt.subplots() Here are some examples… Modify tick label text http://matplotlib.org/examples/pylab_examples/boxplot_demo2.html I see this function used a lot, even though the example is only attempting to create … Read more