The x and y axis scaling in Contour plot - python-3.x

When I make a contour plot with Python, I have been using a set_aspect function. Because this allows me to avoid image/contour-lines distortion caused by changing both axis.
: for example, ax1.set_aspect('equal', 'box-forced')
But, I just found that the option 'box-forced' is not valid in Python3.
So my question is, is there any alternative of the 'box-forced' option in Python3? I want exactly the same effect as the ax1.set_aspect('equal', 'box-forced') in Python2.
Thanks!

I just found that there is a function plt.axis('scaled').
It seems that this does what I wanted in a recent version (3.7) of Python3.

You can try this one from the official documentation that I found in as my first recommended page:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html
I'm not sure what you're trying to accomplish here exactly, but you could try the following:
ax1.set_aspect(aspect='equal', adjustable='box')
You could also check the following link which is for the set_adjustable method:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_anchor.html#matplotlib.axes.Axes.set_anchor
Hope this helps. Good luck!

Related

Turning a Dataframe into a Series with .squeeze("columns")

I'm studying how to work with data right now and so I'm following along with a tutorial for working with Time Series data. Among the first things he does is read_csv on the file path and then use squeeze=True to read it as a Series. Unfortunately (and as you probably know), squeeze has been depricated from read_csv.
I've been reading documentation to figure out how to read a csv as a series, and everything I try fails. The documentation itself says to use pd.read_csv('filename').squeeze('columns') , but, when I check the type afterward, it is always still a Dataframe.
I've looked up various other methods online, but none of them seem to work. I'm doing this on a Jupyter Notebook using Python3 (which the tutorial uses as well).
If anyone has any insights into why I cannot change the type in this way, I would appreciate it. I'm not sure if I've misunderstood the tutorial altogether or if I'm not understanding the documentation.
I do literally type .squeeze("columns") when I write this out because when I write a column name or index, it fails completely. Am I doing that correctly? Is this the correct method or am I missing a better method?
Thanks for the help!
shampoo = pd.read_csv('shampoo_with_exog.csv',index_col= [0], parse_dates=True).squeeze("columns")
I would start with this...
#Change the the stuff between the '' to the entire file path of where your csv is located.
df = pd.read_csv(r'c:\user\documents\shampoo_with_exog.csv')
To start this will name your dataframe as df which is kind of the unspoken industry standard the same as pd for pandas.
Additionally, this will allow you to use a "raw" (the r) string which makes it easier to insert directories into your python code.
Once you are are able to successfully run this you can simply put df in a separate cell in jupyter. This will show you what your data looks like from your CSV. Once you have done all that you can start manipulating your data. While you can use the fancy stuff in pd.read_csv() I mostly just try to get the data and manipulate it from the code itself. Obviously there are reasons not to only do a pd.read_csv but as you progress you can start adding things here and there. I almost never use squeeze although I'm sure there will be those here to comment stating how "essential" it is for whatever the specific case might be.

Creating graphs using code from Pari-GP, but using Sage's graphing tools

everyone!
I know this is probably a dumb question, but I'm having a lot of trouble with Sage, and it's frustrating the hell out of me. To give a bit of an explanation, I code entirely in pari-gp. I don't have a single problem with my code in pari-gp, I'm just having trouble with interfacing my code with Sage. Which, this is something Sage bolsters, that you can run pari-gp code within sage. I essentially want to run all my processes in pari-gp, but I want to exploit all of Sage's graphing protocols.
What I want to do couldn't be easier. I have a well working function test(x,y), which produces a real number. I don't have any problems running this in pari, everything is kosher. All I want to do is make a graph of test(x,y) = z. Now I know how to run this command in sage, but I don't know how to interface such that test is actually a program running from Pari code.
I'd love to program all my stuff in Sage, but that's just impossible. I need the language Pari, so before you say that I could just translate everything in Sage, it's impossible. I just can't wrap my head around how to interface Pari with Sage. I know it's possible; hell, they advertise it on the main website. I'm just very unclear about how to do the following:
1.) Read a file from my pari-gp root directory: gp.read("myfile.gp").
2.) Inherit the functions, such that gp("test(x,y)"), now runs as though it runs in the GP terminal.
3.) Graph said function test(x,y) using Sage's graphing protocols.
Any help is greatly appreciated. I know I'm just forgetting to do something dumb, or I'm missing a step in how I'm doing it.
Any help is greatly appreciated!
Let us start with:
sage: gp("test(x, y) = sin(x*y)")
(x,y)->sin(x*y)
sage: gp("test(1, 1)")
0.84147098480789650665250232163029899962
sage: type(_)
<class 'sage.interfaces.gp.GpElement'>
So the printed version of gp("test(1, 1)") looks like a number, but it is not a float instance. Note that py3 has some f-strings, so we can easily plug in values of variables x, y inside the gp("test(...)") . I will use f-strings to define the sage function...
And we are not far away from the final plot:
sage: f = lambda x, y: float( gp(f"test({x}, {y})") )
sage: plot3d(f, [0, pi], [0, pi])
Launched html viewer for Graphics3d Object

Adding datapoints to a boxplot

R beginner here so sorry for the basic question... I have worked in class to draw some boxplots using the boxplot() function. As part of the assignment I've been asked to add data points to the boxplots. I can't seem to find an argument in the boxplot() function to do this...Is there another function I need to use? Thank you!
I recommend looking into ggplot2 package within R.
You can create multiple visualizations, including a boxplot with the data points shown. This is the ggplot code to do so:
library(ggplot2)
ggplot(df, aes(x=catvar, y=yvar)) +
geom_boxplot()+geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

What the function of checking graph's length(weight) between two nodes in networkx?

I make a Graph by networkx, and it is like that:
now I want to check the distance(weight) between two points, for example point 6 and 7?
Is there some simple syntax can search it like, Graph[6][7]['length']?
You can try this package
https://pypi.org/project/graph-theory/
Check the gd3.distance(n1,n2)

Replacing trigonometric functions in Sympy

I am trying to use Sympy to simplify some trigonometry. I realize that Sympy has a mature set of tools for dealing with this, so it seems like I must be missing something. However, I have spent a lot of time searching and can't seem to find exactly what I am looking for.
Question: How do you expand a simple trig function into its complex components?
MWE:
x = Symbol('x',real=True)
# The following works. Note that it expands cmplx functions into trig fncs
exp(I*x).expand(complex=True)
# Now try to go the other way
expand(sin(x)) #nope
expand_trig(sin(x)) #nope
expand(sin(x),complex=True) #nope
expand_complex(sin(x)) #nope
I also tried replace, rewrite, and xreplace, but didn't get anywhere.

Resources