posit-dev / positron

Positron, a next-generation data science IDE
Other
2.56k stars 80 forks source link

plot window hides elements in a matplotlib chart #5068

Open JosephBARBIERDARNAL opened 22 hours ago

JosephBARBIERDARNAL commented 22 hours ago

System details:

Positron and OS details:

Positron Version: 2024.08.0 (Universal) build 48 Code - OSS Version: 1.91.0 Commit: ed616b36655fb24d116108bdd833f1321704315b Date: 2024-08-19T04:26:51.868Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.6.0

Interpreter details:

Python 3.12.5

Describe the issue:

For example, when I add an annotation to a matplotlib graph, if its position is outside certain values, it will not be displayed in the plot window.

The values in question appear to be outside 0 and 1 in the coordinates of the figure for the x and y axis.

Steps to reproduce the issue:

pip install matplotlib==3.9.2
import matplotlib.pyplot as plt

# not visible
fig, ax = plt.subplots()
fig.text(
    x=0.5, y=1, s='title'
)
plt.show()

# visible
fig, ax = plt.subplots()
fig.text(
    x=0.5, y=0.9, s='title'
)
plt.show()

Image

Expected or desired behavior:

Ideally, the plot window should zoom out (or similar) to ensure that it fits all the elements of the matplotlib figure.

testlabauto commented 20 hours ago

Hi! Thanks for using Positron.

I am not 100% sure if this is an issue with Positron or perhaps just an issue with usage. Could you try this and see if it meets your needs?

import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot()

ax1.title.set_text('Title')

plt.show()

I ask because when i try to repro your original snippet outside Positron, I get the same result and with the snippet I provided, the title looks good.

A larger example: https://stackoverflow.com/questions/25239933/how-to-add-a-title-to-each-subplot

JosephBARBIERDARNAL commented 19 hours ago

It's strange that this works when adding a title, but not when using text().

To be clearer about what I meant in the first place, ideally I should see on the plot window what I would see in a normal notebook or if I saved the plot as a png.

For example, this:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
fig.text(
    x=0.5, y=1, s='title', size=20
)
plt.tight_layout()
plt.savefig('positron.png', bbox_inches='tight')
plt.show()

gives me 2 differents results. positron.png (or what I would have had in a notebook) looks like:

Image

But in positron the plot window gives me:

Image

JosephBARBIERDARNAL commented 19 hours ago

Interestingly, this works perfectly:

import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot()

ax1.set_title('title', y=1.3) # higher position

plt.show()

Image

testlabauto commented 19 hours ago

Thank you for the additional example! I do see what you mean when comparing to a notebook (with the savefig line commented out).

I will move this issue to triage for prioritization.