Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support change the default location of legend in sympy plot. #24429

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

cocolato
Copy link
Contributor

References to other Issues or PRs

Feature support #24339.
Now we can use the legend_loc field to place the legend at the corresponding corner of the axes/figure.
We can refer to the specific enumeration values from matplotlib.legend.Legend.

Brief description of what is fixed or changed

from sympy.plotting import plot, textplot
from sympy import exp
from sympy.abc import x

p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True)
p.save("./my/test1.png")
p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True, legend_loc="lower left")
p.save("./my/test2.png")
p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True, legend_loc="center")
p.save("./my/test3.png")

test1.png
image
test2.png
image
test3.png
image

Other comments

Release Notes

  • plotting
    • Support change the default location of legend in sympy plot.

@sympy-bot
Copy link

sympy-bot commented Dec 26, 2022

Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • plotting
    • Support change the default location of legend in sympy plot. (#24429 by @cocolato)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Feature support https://github.com/sympy/sympy/issues/24339.
Now we can use the legend_loc field to place the legend at the corresponding corner of the axes/figure.
We can refer to the specific enumeration values from [matplotlib.legend.Legend](https://matplotlib.org/stable/api/legend_api.html#module-matplotlib.legend).

#### Brief description of what is fixed or changed

```python
from sympy.plotting import plot, textplot
from sympy import exp
from sympy.abc import x

p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True)
p.save("./my/test1.png")
p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True, legend_loc="lower left")
p.save("./my/test2.png")
p = plot(1/(1+exp(-x)), exp(-x)/(1+exp(-x))**2, (x, -10, 10), \
    show=False, legend=True, legend_loc="center")
p.save("./my/test3.png")
```
test1.png
![image](https://user-images.githubusercontent.com/35182391/209567042-fc454c6e-1a6e-4cf6-a62c-47838be962ef.png)
test2.png
![image](https://user-images.githubusercontent.com/35182391/209567053-132547af-4250-4b7d-9691-30ab51fcee4f.png)
test3.png
![image](https://user-images.githubusercontent.com/35182391/209567073-030220ee-16f7-4acf-9fee-be74aef7316f.png)

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* plotting
  * Support change the default location of legend in sympy plot.
<!-- END RELEASE NOTES -->

@cocolato cocolato force-pushed the feat/support_matplotlib_legend_loc branch from 472b985 to f5c71b9 Compare December 26, 2022 16:44
@github-actions
Copy link

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [41d90958]       [a44d1a27]
     <sympy-1.11.1^0>                 
-         952±2μs          624±2μs     0.66  solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
-     2.74±0.01ms         1.17±0ms     0.43  solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
-     5.49±0.04ms         1.72±0ms     0.31  solve.TimeSparseSystem.time_linear_eq_to_matrix(30)

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

sympy/plotting/plot.py Outdated Show resolved Hide resolved
@cocolato cocolato requested a review from sylee957 June 14, 2023 15:27
@cocolato
Copy link
Contributor Author

Not sure why ci reported the error.

@cocolato cocolato closed this Feb 8, 2024
@cocolato cocolato reopened this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants