Skip to content

Commit 9db05f2

Browse files
committed
plotly fixes
1 parent 18c78d5 commit 9db05f2

File tree

3 files changed

+2024
-80
lines changed

3 files changed

+2024
-80
lines changed

src/maxplotlib/backends/matplotlib/utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,19 @@ def set_size(width, fraction=1, ratio="golden"):
6363
width_pt = width
6464

6565
fig_width_pt = width_pt * fraction
66-
inches_per_pt = 1 / 72.27
66+
#inches_per_pt = 1 / 72.27
6767

6868
# Calculate the figure height based on the desired ratio
6969
if ratio == "golden":
7070
golden_ratio = (5**0.5 - 1) / 2
71-
fig_height_in = fig_width_pt * inches_per_pt * golden_ratio
71+
fig_height_pt = fig_width_pt * golden_ratio
7272
elif ratio == "square":
73-
fig_height_in = fig_width_pt * inches_per_pt
73+
fig_height_pt = fig_width_pt
7474
elif isinstance(ratio, (int, float)):
75-
fig_height_in = fig_width_pt * inches_per_pt * ratio
75+
fig_height_pt = fig_width_pt * ratio
7676
else:
7777
raise ValueError("Invalid ratio specified.")
78-
79-
fig_width_in = fig_width_pt * inches_per_pt
80-
fig_dim = (fig_width_in, fig_height_in)
78+
fig_dim = (fig_width_pt, fig_height_pt)
8179
return fig_dim
8280

8381
def create_lineplot(

src/maxplotlib/canvas/canvas.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self, **kwargs):
2222
self._description = kwargs.get('description', None)
2323
self._label = kwargs.get('label', None)
2424

25+
self._dpi=kwargs.get('dpi', 300)
2526
self._width=kwargs.get('width', 426.79135)
2627
self._ratio=kwargs.get('ratio', "golden")
2728
self._gridspec_kw = kwargs.get('gridspec_kw', {"wspace": 0.08, "hspace": 0.1})
@@ -106,7 +107,8 @@ def plot_matplotlib(self, show=True, savefig=False):
106107
else:
107108
fig_width, fig_height = plt_utils.set_size(width=self._width, ratio=self._ratio)
108109

109-
fig, axes = plt.subplots(self.nrows, self.ncols, figsize=(fig_width, fig_height), squeeze=False)
110+
print(fig_width, fig_height, fig_width / self._dpi, fig_height / self._dpi)
111+
fig, axes = plt.subplots(self.nrows, self.ncols, figsize=(fig_width / self._dpi, fig_height / self._dpi), squeeze=False, dpi = self._dpi)
110112

111113
for (row, col), line_plot in self.subplots.items():
112114
ax = axes[row][col]
@@ -138,7 +140,7 @@ def plot_plotly(self, show=True, savefig=None):
138140
fig_width, fig_height = self._figsize
139141
else:
140142
fig_width, fig_height = plt_utils.set_size(width=self._width, ratio=self._ratio)
141-
143+
print(self._width, fig_width, fig_height)
142144
# Create subplots
143145
fig = make_subplots(rows=self.nrows, cols=self.ncols, subplot_titles=[
144146
f"Subplot ({row}, {col})" for (row, col) in self.subplots.keys()
@@ -152,8 +154,8 @@ def plot_plotly(self, show=True, savefig=None):
152154

153155
# Update layout settings
154156
fig.update_layout(
155-
width=fig_width,
156-
height=fig_height,
157+
# width=fig_width,
158+
# height=fig_height,
157159
font=dict(size=fontsize),
158160
margin=dict(l=10, r=10, t=40, b=10), # Adjust margins if needed
159161
)
@@ -169,6 +171,11 @@ def plot_plotly(self, show=True, savefig=None):
169171

170172

171173
# Property getters
174+
175+
@property
176+
def dpi(self):
177+
return self._dpi
178+
172179
@property
173180
def nrows(self):
174181
return self._nrows
@@ -198,6 +205,10 @@ def subplot_matrix(self):
198205
return self._subplot_matrix
199206

200207
# Property setters
208+
@nrows.setter
209+
def dpi(self, value):
210+
self._dpi = value
211+
201212
@nrows.setter
202213
def nrows(self, value):
203214
self._nrows = value

tutorials/tutorial_1.ipynb

Lines changed: 2004 additions & 69 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)