Open gmvelez opened 6 years ago
plt.show()
will produce your plot in a separate window on your machine.
Thanks for the quick response! When I do that the output line disappears, but nothing opens still. Could it be something with my settings?
Ok yes it is probably something to do with how you installed matplotlib. Within that realm, there are a couple of things that could be happening. Let's try looking at the backend configuration of your matplotlib first.
(1) Open your terminal and enter in the following command to get the file and path and name of your matplotlib setup/config file:
matplotlib.matplotlib_fname()
(2) Copy the file path and name that comes up and open that file either in a text editor or vim (whichever you'd feel comfortable with)
open filepath/filename
(this should just open your default text editor depending on how your machine is set up) vim filepath/filename
(3) You need to find where your backend is specified. If your file is the same as the one I have on my machine (which theoretically it is), there should be a comment #### CONFIGURATION BEGINS HERE
. The next line of uncommented code is what you want to look at. On my machine it's backend : macosx
but I'm guessing that on yours the backend could be set to template. Change it to either macosx
(if you have a mac) or another one of the default backends provided (I've heard that GtkAgg
is a good option).
(4) Once you've saved the file you should be able to run your program and see your plots.
Let me know if this doesn't work for you- as I said there are a few different things that could be happening here. Also feel free to come to office hours if you're (rightly) confused about this stuff.
Thanks for this detailed step by step. When I enter the first line in the terminal, nothing happens.
I might not be able to make it to office hours to figure this out (sorry I didn't realize this yesterday during lab!)
Oh yes of course- sorry I forgot to explicitly specify that before you do any of this you have to enter into a python environment in your terminal with the command ipython3
assuming you're using python3 and not a previous iteration. Then import matplotlib
and find the filename with the matplotlib.matplotlib_fname()
command. Once you have the filepath and name you can exit out of the ipython environment.
Thanks - so I went through and checked, and the backend is set to macosx already.
Hmm cool. Could you try saving the figure instead of showing it?
plt.savefig('fig.png')
Does this command save the figure for you?
Hello,
I ran the first two chunks of code to input the data for assignment 2 and to get the histogram. When I try to do the next part, it says Out3: <matplotlib.legend.Legend at 0x1a12cfaef0>
This is my code:
def truncnorm_pdf(xvals, mu, sigma, cutoff): if cutoff == 'None': prob_notcut = 1.0 - sts.norm.cdf(0, loc=mu, scale=sigma) else: prob_notcut = (sts.norm.cdf(cutoff, loc=mu, scale=sigma) - sts.norm.cdf(0, loc=mu, scale=sigma))
mu_1 = 11 sig_1 = 0.5 plt.plot(incomes, truncnorm_pdf(incomes, mu_1, sig_1, 15000), linewidth=2, color='r', label='1: $\mu$=11,$\sigma$=0.5') plt.legend(loc='upper left')
Thanks!