1

I know this may sound like a nooby question but I am new to python and am trying to graph some stock data using pandas. I know this is not technically a programming question but do I need to install anything special for the graph to print or does it just graph in the IDE console? Or none of the above? Thanks in advance

Cachario
  • 41
  • 1
  • 1
  • 6
  • [how to install matplotlib](https://matplotlib.org/users/installing.html) – sacuL Aug 06 '18 at 23:35
  • What do you mean "for the graph to print", "does it just graph in the IDE console"? Do you have a python script that includes `matplotlib` module but the script's execution does not create a GUI window? Look into some of the examples in the tutorials https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py – chickity china chinese chicken Aug 06 '18 at 23:38
  • "in the IDE console"... which IDE are you using? It will display in-console with jupyter notebook, and I think some other Ipython variants. From the interpreter in a terminal it opens a new window... – Him Aug 06 '18 at 23:39
  • In order to plot things with pandas you need to have matplotlib installed. Now that might already come with your distribution, or if not you need to install it, usually through the same channel as you have installed pandas. A popular distribution is (ana)conda, in which case you'd do `conda install matplotlib`. – ImportanceOfBeingErnest Aug 06 '18 at 23:40
  • Post your code. I suspect, if you are having trouble "showing" the graph, you may be missing a particular command.... – Him Aug 06 '18 at 23:40
  • @Scott 1) I am using the PyCharm IDE. 2) I am just wondering what the data is displayed in. However, just to test if I can import matplotlib into a program, I typed import matplotlib.pyplot as plt, and there was an import error saying "import matplotlib.pyplot as plt ImportError: No module named matplotlib.pyplot" I also have then same issue with pandas- https://stackoverflow.com/questions/51700018/no-module-named-pandas/51700041?noredirect=1#comment90393264_51700041 – Cachario Aug 06 '18 at 23:49
  • So how did you install python? – ImportanceOfBeingErnest Aug 06 '18 at 23:54
  • I installed it locally at python's website. I also installed anaconda – Cachario Aug 06 '18 at 23:55
  • For the beginning I would recommend not having two python versions installed. Choose one, uninstall the other. If you decide for the one from python's website, use `pip install pandas matplotlib`. If you decide for anaconda use `conda install pandas matplotlib`. – ImportanceOfBeingErnest Aug 07 '18 at 00:15
  • ok I just deleted anaconda and used pip install pandas matplotlib but to no avail in PyCharm. By the way thanks for all the help and dealing with someone that isnt very educated in programming – Cachario Aug 07 '18 at 00:23
  • Is this PyCharm specific? I.e. can you create a file in an editor and run it as python script? – ImportanceOfBeingErnest Aug 07 '18 at 12:50
  • Correct I use the pip install command in the terminal for Mac, then I can create a Python file in PyCharm and run it as a python script – Cachario Aug 07 '18 at 17:18
  • What I meant is: Does it work if you don't use PyCharm? – ImportanceOfBeingErnest Aug 08 '18 at 10:31
  • I know this is not related to your question but I have figured out why it will not work. On another thread I have talked to another person about why pandas would not work, and I did everything he told me to do and nothing would solve it. Then I looked up online the differences between the paid and free versions of PyCharm (I have the free version). I then read that some of the things the free version does not include is the ability to use pandas, matplotlib, or numpy. Relating to your question, I am not sure because I do not have any other IDE – Cachario Aug 08 '18 at 11:13
  • Ähm, no. I do have the free version of PyCharm installed (version 2017.1.1) and it works with matplotlib and pandas. – ImportanceOfBeingErnest Aug 08 '18 at 14:42
  • No, you do not need to use the PyCharm packagemanager (but you may presumably). – ImportanceOfBeingErnest Aug 08 '18 at 23:10
  • I'm not sure why it works for you @ImportanceOfBeingErnest https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html and click scientific tools so I am not sure why it still displays the error message – Cachario Aug 08 '18 at 23:34
  • but maybe some valuable information you may want to know is for some reason the pip install returns an error message without anaconda installed. Shouldnt it work without anaconda? I still have downloaded the libraries with pip though – Cachario Aug 08 '18 at 23:39
  • PyCharm wants to make money, so they sell "scientific tool support", which means that the payed version may have some additional features to "ease" the visualizations. This is not related to running a simple pandas/matplotlib code. Yes, pip install should work without anaconda. If it doesn't that may be the root of the problem, namely some conflicts between python versions. – ImportanceOfBeingErnest Aug 09 '18 at 00:00
  • In any case, I would ignore PyCharm for the moment. The first thing to make sure is that you can run something like `python -c "import matplotlib"` in your terminal. Only once that works you may start thinking about using an IDE. – ImportanceOfBeingErnest Aug 09 '18 at 00:29
  • That code does work in the terminal – Cachario Aug 09 '18 at 00:33
  • I might have misunderstood that. In that case, you can look at [the PyCharm settings](https://i.stack.imgur.com/0Omap.png) to make sure you are using the correct interpreter, namely the one that is used when typing `python` in the terminal. – ImportanceOfBeingErnest Aug 09 '18 at 01:28
  • I am. Would you suggest trying to use another IDE and see if that would work? If so, which one should I download? – Cachario Aug 09 '18 at 01:38

1 Answers1

0

Welcome to the world of python programming!

To graph using Matplotlib, first you would have to ensure it is installed in your system:

pip install matplotlib

And then import it into your code using

import matplotlib.pyplot as plt           #import the plotting method in Matplotlib

Following this import and creating your plot, you can have your plot shown using

plt.show()                               
alephnerd
  • 2,176
  • 1
  • 8
  • 6